From 11a07f4d063048de73bf2db9d984fbb02ca55501 Mon Sep 17 00:00:00 2001 From: 0xRob <83790096+0xRobin@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:35:51 +0100 Subject: [PATCH 01/17] Fix for kyberswap aggregator: ignore 1 specific token (#7352) * ignore 1 specific token * syntax --- .../kyberswap_aggregator_avalanche_c_trades.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/kyberswap/avalanche_c/kyberswap_aggregator_avalanche_c_trades.sql b/dbt_subprojects/dex/models/_projects/kyberswap/avalanche_c/kyberswap_aggregator_avalanche_c_trades.sql index 635d3fb2724..2061a3ddc8b 100644 --- a/dbt_subprojects/dex/models/_projects/kyberswap/avalanche_c/kyberswap_aggregator_avalanche_c_trades.sql +++ b/dbt_subprojects/dex/models/_projects/kyberswap/avalanche_c/kyberswap_aggregator_avalanche_c_trades.sql @@ -1,6 +1,6 @@ {{ config ( - + schema = 'kyberswap_aggregator_avalanche_c', alias = 'trades', partition_by = ['block_month'], @@ -36,8 +36,11 @@ WITH meta_router AS ,ARRAY[-1] AS trace_address FROM {{ source('kyber_avalanche_c', 'MetaAggregationRouterV2_evt_Swapped') }} + WHERE 0x250f8f7750735e3ab5dc9db3a542f6b71999ed38 not in (dstToken, srcToken) + -- There are 2 weird transactions with this token where the return and spent amounts in the event are not correct + -- these result in inflated volume, so we'll ignore this token in any trades. {% if is_incremental() %} - WHERE evt_block_time >= date_trunc('day', now() - INTERVAL '7' DAY) + AND evt_block_time >= date_trunc('day', now() - INTERVAL '7' DAY) {% endif %} ) SELECT From dbf8c8675eda2be5b1f7518892a159ef3939c103 Mon Sep 17 00:00:00 2001 From: Peter <49856481+peterrliem@users.noreply.github.com> Date: Fri, 20 Dec 2024 00:07:44 +0800 Subject: [PATCH 02/17] Add Sovrun to ethereum tokens (#7345) * Update prices_ethereum_tokens.sql Add SOVRUN token * Update prices_ethereum_tokens.sql --- .../tokens/models/prices/ethereum/prices_ethereum_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql index 78c535ee76b..61dafea3763 100644 --- a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql @@ -1870,7 +1870,8 @@ FROM ('sigma2-sigma', 'ethereum', 'SIGMA', 0x18a8D75F70eAEad79B5A55903D036ce337F623A5, 18), ('mstr-mstr2100', 'ethereum', 'MSTR', 0x42069026EAC8Eee0Fd9b5f7aDFa4f6E6D69a2B39, 9), ('usdl-lift-dollar', 'ethereum', 'USDL', 0xbdC7c08592Ee4aa51D06C27Ee23D5087D65aDbcD, 18), - ('usr-resolv-usr', 'ethereum', 'USR', 0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110, 18) + ('usr-resolv-usr', 'ethereum', 'USR', 0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110, 18), + ('sovrn-sovrun','ethereum', 'SOVRN', 0x031B8d752d73d7Fe9678ACEf26e818280D0646b4, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( -- bad price feeds From 8b0b3ae9a21305ce0b42e4c9572eed244486b932 Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Thu, 19 Dec 2024 16:08:00 +0000 Subject: [PATCH 03/17] Add COW Token on Base (#7347) --- .../tokens/models/tokens/base/tokens_base_erc20.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql index a7feaeee8e3..ca5c1937e5b 100644 --- a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20.sql @@ -409,5 +409,6 @@ FROM (VALUES , (0x5f7373Fa845692b1dD7bfaE576D6c743482bf26a, 'CLARK', 18) , (0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842, 'MORPHO', 18) , (0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8, 'GYD', 18) - , (0xC0D3700000987C99b3C9009069E4f8413fD22330, 'cdxUSD', 18) + , (0xC0D3700000987C99b3C9009069E4f8413fD22330, 'cdxUSD', 18) + , (0xc694a91e6b071bf030a18bd3053a7fe09b6dae69, 'COW', 18) ) AS temp_table (contract_address, symbol, decimals) From 8e5a985496bbb473df0430df071f0bdf3493ce90 Mon Sep 17 00:00:00 2001 From: Jacob Sharples <45126111+JacobSharples@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:08:11 -0500 Subject: [PATCH 04/17] Update prices_base_tokens.sql (#7349) * Update prices_base_tokens.sql * Update prices_base_tokens.sql * Update prices_base_tokens.sql --- .../tokens/models/prices/base/prices_base_tokens.sql | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql index 2cc0457de62..00c4e28e4b5 100644 --- a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql @@ -193,5 +193,15 @@ FROM ('alb-alienbase', 'base', 'ALB',0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4, 18), ('clark-coinbase-mascot','base','CLARK',0x5f7373Fa845692b1dD7bfaE576D6c743482bf26a, 18), ('gyd-gyro-dollar','base','GYD',0xca5d8f8a8d49439357d3cf46ca2e720702f132b8, 18), - ('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18) + ('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18), + ('bomb-fbomb', 'base', 'BOMB', 0x74ccbe53f77b08632ce0cb91d3a545bf6b8e0979, 18), + ('play9-play', 'base', 'PLAY', 0x7404ac09adf614603d9c16a7ce85a1101f3514ba, 18), + ('champ-super-champs', 'base', 'CHAMP', 0xeb6d78148f001f3aa2f588997c5e102e489ad341, 18), + ('euroc-euro-coin', 'base', 'EURC', 0x60a3e35cc302bfa44cb288bc5a4f316fdb1adb42, 6), + ('fai-freysa', 'base', 'FAI', 0xb33ff54b9f7242ef1593d2c9bcd8f9df46c77935, 18), + ('ogn-origin-protocol', 'base', 'OGN', 0x7002458b1df59eccb57387bc79ffc7c29e22e6f7, 18), + ('usdt-tether', 'base', 'USDT', 0xfde4c96c8593536e31f229ea8f37b2ada2699bb2, 6), + ('klima-klimadao', 'base', 'KLIMA', 0xdcefd8c8fcc492630b943abcab3429f12ea9fea2, 9), + ('yfi-yearnfinance', 'base', 'YFI', 0x9eaf8c1e34f05a589eda6bafdf391cf6ad3cb239, 18) + --('well-moonwell' ,'base', 'WELL', 0xa88594d404727625a9437c3f886c7643872296ae, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) From 937765c00a24b8e9cf3b7196281e64c7eb2c87c4 Mon Sep 17 00:00:00 2001 From: Lydia Puspita <113081740+lydiapuspita@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:08:21 +0700 Subject: [PATCH 05/17] Add HYPE, TANK, MEMESAI, GRIFT, GRIFFAIN, and FXN token price (#7353) * Update prices_native_tokens.sql Add HYPE token price * Update prices_solana_tokens.sql Add TANK, MEMESAI, GRIFT, GRIFFAIN, and FXN token price --------- Co-authored-by: Huang Geyang --- .../tokens/models/prices/prices_native_tokens.sql | 3 ++- .../tokens/models/prices/solana/prices_solana_tokens.sql | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql b/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql index 978c1669a8c..e7bc5483e81 100644 --- a/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/prices_native_tokens.sql @@ -88,5 +88,6 @@ FROM ('ton-toncoin', null, 'TON', null,null), ('strk-starknet', null, 'STRK', null,null), ('kda-kadena', null, 'KDA', null, null), - ('ron-ronin-token', null, 'RON', null, null) + ('ron-ronin-token', null, 'RON', null, null), + ('hype-hyperliquid', null, 'HYPE', null, null) ) as temp (token_id, blockchain, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/prices/solana/prices_solana_tokens.sql b/dbt_subprojects/tokens/models/prices/solana/prices_solana_tokens.sql index 6feb9cdbd4d..9ba81a4fa10 100644 --- a/dbt_subprojects/tokens/models/prices/solana/prices_solana_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/solana/prices_solana_tokens.sql @@ -710,5 +710,10 @@ FROM ('goat-goatseus-maximus', 'solana', 'GOAT', 'CzLSujWBLFsSjncfkh59rUFqvafWcY5tzedWJSuypump', 6), ('fwog-fwog', 'solana', 'FWOG', 'A8C3xuqscfmyLrte3VmTqrAq8kgMASius9AFNANwpump', 6), ('lester-litecoin-mascot', 'solana', 'LESTER', '5z3iCe53hUANTiG8Js8RjHNE2Arjik7L2CXLyr2rpump', 6), - ('happy-happycat', 'solana', 'HAPPY', 'HAPPYwgFcjEJDzRtfWE6tiHE9zGdzpNky2FvjPHsvvGZ', 9) + ('happy-happycat', 'solana', 'HAPPY', 'HAPPYwgFcjEJDzRtfWE6tiHE9zGdzpNky2FvjPHsvvGZ', 9), + ('memesai-memes-ai', 'solana', 'MEMESAI', '39qibQxVzemuZTEvjSB7NePhw9WyyHdQCqP8xmBMpump', 6), + ('grift1-orbit', 'solana', 'GRIFT', 'GekTNfm84QfyP2GdAHZ5AgACBRd69aNmgA5FDhZupump', 6), + ('fxn-fxn', 'solana', 'FXN', '92cRC6kV5D7TiHX1j56AbkPbffo9jwcXxSDQZ8Mopump',6), + ('griffain-test-griffaincom', 'solana', 'GRIFFAIN', 'KENJSUYLASHUMfHyy5o4Hp2FdNqZg1AsUPhfH2kYvEP', 6), + ('tank-agenttank', 'solana', 'TANK', 'GAMwtMB6onAvBNBQJCJFuxoaqfPH8uCQ2dewNMVVpump', 6) ) as temp (token_id, blockchain, symbol, contract_address, decimals) From 97074e0ab42cc7fa67af2c077fbbc5d69f01a432 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:08:29 +0000 Subject: [PATCH 06/17] Update tokens_ethereum_erc20.sql (#7356) --- .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 96bf183c18c..c83ece387c6 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4740,4 +4740,5 @@ FROM (VALUES , ( 0xa4f6b2cdcb67bf8f48baa459a333d2667aa4b100, 'shezETH', 8) , ( 0x7F4B66FF703336CfC35b901144614496Ae0b0D27, 'shezUSD', 18) , ( 0xa7b66dda0d7c7c1e43d3130491216172993d163d, 'EVS', 6) + , ( 0x2371e134e3455e0593363cbf89d3b6cf53740618, 'gtWETH', 18) ) AS temp_table (contract_address, symbol, decimals) From 52365499faac1ed8c57044b2dc7fa15a35a50673 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 20 Dec 2024 00:08:49 +0800 Subject: [PATCH 07/17] Init ton source (#7342) --- .../_base_sources/other/ton_base_sources.yml | 920 ++++++++++++++++++ 1 file changed, 920 insertions(+) create mode 100644 sources/_base_sources/other/ton_base_sources.yml diff --git a/sources/_base_sources/other/ton_base_sources.yml b/sources/_base_sources/other/ton_base_sources.yml new file mode 100644 index 00000000000..55770d278b7 --- /dev/null +++ b/sources/_base_sources/other/ton_base_sources.yml @@ -0,0 +1,920 @@ +version: 2 + +sources: + - name: ton + description: "TON blockchain raw data tables" + freshness: + warn_after: { count: 12, period: hour } + error_after: { count: 24, period: hour } + tables: + - name: blocks + loaded_at_field: ingested_at + description: "TON blockchain blocks" + columns: + - name: block_time + description: "Block timestamp" + tests: + - not_null + data_type: timestamp + + - name: block_date + description: "Block date" + tests: + - not_null + data_type: date + + - name: workchain + description: "Workchain identifier" + data_type: integer + + - name: shard + description: "Shard identifier" + data_type: bigint + + - name: seqno + description: "Block sequence number" + data_type: integer + + - name: root_hash + description: "Root hash of the block" + data_type: varchar + + - name: file_hash + description: "File hash of the block" + data_type: varchar + + - name: mc_block_workchain + description: "Masterchain block workchain" + data_type: integer + + - name: mc_block_shard + description: "Masterchain block shard" + data_type: bigint + + - name: mc_block_seqno + description: "Masterchain block sequence number" + data_type: integer + + - name: global_id + description: "Global identifier" + data_type: integer + + - name: version + description: "Block version" + data_type: integer + + - name: after_merge + description: "Flag indicating if block is after merge" + data_type: boolean + + - name: before_split + description: "Flag indicating if block is before split" + data_type: boolean + + - name: after_split + description: "Flag indicating if block is after split" + data_type: boolean + + - name: want_merge + description: "Flag indicating if block wants to merge" + data_type: boolean + + - name: want_split + description: "Flag indicating if block wants to split" + data_type: boolean + + - name: key_block + description: "Flag indicating if block is a key block" + data_type: boolean + + - name: vert_seqno_incr + description: "Vertical sequence number increment flag" + data_type: boolean + + - name: flags + description: "Block flags" + data_type: integer + + - name: gen_utime + description: "Generation unix time" + data_type: bigint + + - name: start_lt + description: "Start logical time" + data_type: bigint + + - name: end_lt + description: "End logical time" + data_type: bigint + + - name: validator_list_hash_short + description: "Short hash of validator list" + data_type: integer + + - name: gen_catchain_seqno + description: "Generation catchain sequence number" + data_type: integer + + - name: min_ref_mc_seqno + description: "Minimum reference masterchain sequence number" + data_type: integer + + - name: prev_key_block_seqno + description: "Previous key block sequence number" + data_type: integer + + - name: vert_seqno + description: "Vertical sequence number" + data_type: integer + + - name: master_ref_seqno + description: "Master reference sequence number" + data_type: integer + + - name: rand_seed + description: "Random seed" + data_type: varchar + + - name: created_by + description: "Block creator address" + data_type: varchar + + - name: tx_count + description: "Number of transactions in block" + data_type: integer + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the block was ingested" + data_type: timestamp + + - name: messages + loaded_at_field: ingested_at + description: "TON blockchain messages" + columns: + - name: block_time + description: "Block timestamp" + data_type: timestamp + + - name: block_date + description: "Block date" + data_type: date + + - name: tx_hash + description: "Transaction hash" + data_type: varchar + + - name: tx_lt + description: "Transaction logical time" + data_type: bigint + + - name: tx_now + description: "Transaction timestamp" + data_type: integer + + - name: msg_hash + description: "Message hash" + data_type: varchar + + - name: direction + description: "Message direction" + data_type: varchar + + - name: trace_id + description: "Trace identifier" + data_type: varchar + + - name: source + description: "Source address" + data_type: varchar + + - name: destination + description: "Destination address" + data_type: varchar + + - name: value + description: "Message value" + data_type: bigint + + - name: fwd_fee + description: "Forward fee" + data_type: bigint + + - name: ihr_fee + description: "IHR fee" + data_type: bigint + + - name: created_lt + description: "Creation logical time" + data_type: bigint + + - name: created_at + description: "Creation timestamp" + data_type: bigint + + - name: opcode + description: "Operation code" + data_type: integer + + - name: ihr_disabled + description: "IHR disabled flag" + data_type: boolean + + - name: bounce + description: "Bounce flag" + data_type: boolean + + - name: bounced + description: "Bounced flag" + data_type: boolean + + - name: import_fee + description: "Import fee" + data_type: bigint + + - name: body_hash + description: "Message body hash" + data_type: varchar + + - name: body_boc + description: "Message body BOC" + data_type: varbinary + + - name: comment + description: "Message comment" + data_type: varchar + + - name: init_state_hash + description: "Initial state hash" + data_type: varchar + + - name: init_state_boc + description: "Initial state BOC" + data_type: varbinary + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the message was ingested" + data_type: timestamp + + - name: transactions + loaded_at_field: ingested_at + description: "TON blockchain transactions" + columns: + - name: block_time + description: "Block timestamp" + data_type: timestamp + + - name: block_date + description: "Block date" + data_type: date + + - name: account + description: "Account address" + data_type: varchar + + - name: hash + description: "Transaction hash" + data_type: varchar + + - name: lt + description: "Logical time" + data_type: bigint + + - name: block_workchain + description: "Block workchain identifier" + data_type: integer + + - name: block_shard + description: "Block shard identifier" + data_type: bigint + + - name: block_seqno + description: "Block sequence number" + data_type: integer + + - name: mc_block_seqno + description: "Masterchain block sequence number" + data_type: integer + + - name: trace_id + description: "Trace identifier" + data_type: varchar + + - name: prev_trans_hash + description: "Previous transaction hash" + data_type: varchar + + - name: prev_trans_lt + description: "Previous transaction logical time" + data_type: bigint + + - name: now + description: "Transaction timestamp" + data_type: integer + + - name: orig_status + description: "Original status" + data_type: varchar + + - name: end_status + description: "End status" + data_type: varchar + + - name: total_fees + description: "Total transaction fees" + data_type: bigint + + - name: account_state_hash_before + description: "Account state hash before transaction" + data_type: varchar + + - name: account_state_hash_after + description: "Account state hash after transaction" + data_type: varchar + + - name: account_state_code_hash_before + description: "Account state code hash before transaction" + data_type: varchar + + - name: account_state_code_hash_after + description: "Account state code hash after transaction" + data_type: varchar + + - name: account_state_balance_before + description: "Account balance before transaction" + data_type: bigint + + - name: account_state_balance_after + description: "Account balance after transaction" + data_type: bigint + + - name: descr + description: "Transaction description" + data_type: varchar + + - name: aborted + description: "Transaction aborted flag" + data_type: boolean + + - name: destroyed + description: "Account destroyed flag" + data_type: boolean + + - name: credit_first + description: "Credit first flag" + data_type: boolean + + - name: is_tock + description: "Is tock transaction flag" + data_type: boolean + + - name: installed + description: "Code installed flag" + data_type: boolean + + - name: storage_fees_collected + description: "Storage fees collected" + data_type: bigint + + - name: storage_fees_due + description: "Storage fees due" + data_type: bigint + + - name: storage_status_change + description: "Storage status change" + data_type: varchar + + - name: credit_due_fees_collected + description: "Credit due fees collected" + data_type: bigint + + - name: credit + description: "Credit amount" + data_type: bigint + + - name: compute_skipped + description: "Compute phase skipped flag" + data_type: boolean + + - name: skipped_reason + description: "Reason for skipping compute phase" + data_type: varchar + + - name: compute_success + description: "Compute phase success flag" + data_type: boolean + + - name: compute_msg_state_used + description: "Message state used in compute phase" + data_type: boolean + + - name: compute_account_activated + description: "Account activated in compute phase" + data_type: boolean + + - name: compute_gas_fees + description: "Gas fees in compute phase" + data_type: bigint + + - name: compute_gas_used + description: "Gas used in compute phase" + data_type: bigint + + - name: compute_gas_limit + description: "Gas limit in compute phase" + data_type: bigint + + - name: compute_gas_credit + description: "Gas credit in compute phase" + data_type: bigint + + - name: compute_mode + description: "Compute phase mode" + data_type: integer + + - name: compute_exit_code + description: "Compute phase exit code" + data_type: integer + + - name: compute_exit_arg + description: "Compute phase exit argument" + data_type: integer + + - name: compute_vm_steps + description: "VM steps in compute phase" + data_type: bigint + + - name: compute_vm_init_state_hash + description: "VM initial state hash" + data_type: varchar + + - name: compute_vm_final_state_hash + description: "VM final state hash" + data_type: varchar + + - name: action_success + description: "Action phase success flag" + data_type: boolean + + - name: action_valid + description: "Action phase validity flag" + data_type: boolean + + - name: action_no_funds + description: "No funds for action phase flag" + data_type: boolean + + - name: action_status_change + description: "Action phase status change" + data_type: varchar + + - name: action_total_fwd_fees + description: "Total forward fees in action phase" + data_type: bigint + + - name: action_total_action_fees + description: "Total action fees" + data_type: bigint + + - name: action_result_code + description: "Action phase result code" + data_type: integer + + - name: action_result_arg + description: "Action phase result argument" + data_type: integer + + - name: action_tot_actions + description: "Total number of actions" + data_type: integer + + - name: action_spec_actions + description: "Number of special actions" + data_type: integer + + - name: action_skipped_actions + description: "Number of skipped actions" + data_type: integer + + - name: action_msgs_created + description: "Number of messages created" + data_type: integer + + - name: action_action_list_hash + description: "Action list hash" + data_type: varchar + + - name: action_tot_msg_size_cells + description: "Total message size in cells" + data_type: bigint + + - name: action_tot_msg_size_bits + description: "Total message size in bits" + data_type: bigint + + - name: bounce + description: "Bounce status" + data_type: varchar + + - name: bounce_msg_size_cells + description: "Bounce message size in cells" + data_type: bigint + + - name: bounce_msg_size_bits + description: "Bounce message size in bits" + data_type: bigint + + - name: bounce_req_fwd_fees + description: "Required forward fees for bounce" + data_type: bigint + + - name: bounce_msg_fees + description: "Bounce message fees" + data_type: bigint + + - name: bounce_fwd_fees + description: "Bounce forward fees" + data_type: bigint + + - name: split_info_cur_shard_pfx_len + description: "Current shard prefix length" + data_type: integer + + - name: split_info_acc_split_depth + description: "Account split depth" + data_type: integer + + - name: split_info_this_addr + description: "This address in split info" + data_type: varchar + + - name: split_info_sibling_addr + description: "Sibling address in split info" + data_type: varchar + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the transaction was ingested" + data_type: timestamp + + - name: dex_pools + loaded_at_field: ingested_at + description: "TON DEX pools information" + columns: + - name: block_time + description: "Block timestamp" + data_type: timestamp + + - name: block_date + description: "Block date" + data_type: date + + - name: pool + description: "Pool address" + data_type: varchar + + - name: project + description: "DEX project name" + data_type: varchar + + - name: version + description: "DEX version" + data_type: integer + + - name: discovered_at + description: "Pool discovery timestamp" + data_type: integer + + - name: jetton_left + description: "Left token address" + data_type: varchar + + - name: jetton_right + description: "Right token address" + data_type: varchar + + - name: reserves_left + description: "Left token reserves" + data_type: decimal(38,0) + + - name: reserves_right + description: "Right token reserves" + data_type: decimal(38,0) + + - name: total_supply + description: "Total supply of LP tokens" + data_type: decimal(38,0) + + - name: tvl_usd + description: "Total value locked in USD" + data_type: decimal(20,6) + + - name: tvl_ton + description: "Total value locked in TON" + data_type: decimal(20,9) + + - name: last_updated + description: "Last update timestamp" + data_type: integer + + - name: is_liquid + description: "Liquidity status flag" + data_type: boolean + + - name: lp_fee + description: "LP fee percentage" + data_type: decimal(12,10) + + - name: protocol_fee + description: "Protocol fee percentage" + data_type: decimal(12,10) + + - name: referral_fee + description: "Referral fee percentage" + data_type: decimal(12,10) + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the pool data was ingested" + data_type: timestamp + + - name: dex_trades + loaded_at_field: ingested_at + description: "TON DEX trades information" + columns: + - name: block_time + description: "Block timestamp" + data_type: timestamp + + - name: block_date + description: "Block date" + data_type: date + + - name: tx_hash + description: "Transaction hash" + data_type: varchar + + - name: trace_id + description: "Trace identifier" + data_type: varchar + + - name: project_type + description: "Project type" + data_type: varchar + + - name: project + description: "DEX project name" + data_type: varchar + + - name: version + description: "DEX version" + data_type: integer + + - name: event_time + description: "Event timestamp" + data_type: integer + + - name: event_type + description: "Event type" + data_type: varchar + + - name: trader_address + description: "Trader address" + data_type: varchar + + - name: pool_address + description: "Pool address" + data_type: varchar + + - name: router_address + description: "Router address" + data_type: varchar + + - name: token_sold_address + description: "Sold token address" + data_type: varchar + + - name: token_bought_address + description: "Bought token address" + data_type: varchar + + - name: amount_sold_raw + description: "Raw amount of tokens sold" + data_type: decimal(38,0) + + - name: amount_bought_raw + description: "Raw amount of tokens bought" + data_type: decimal(38,0) + + - name: referral_address + description: "Referral address" + data_type: varchar + + - name: platform_tag + description: "Platform tag" + data_type: varchar + + - name: query_id + description: "Query identifier" + data_type: decimal(20,0) + + - name: volume_usd + description: "Trade volume in USD" + data_type: decimal(20,6) + + - name: volume_ton + description: "Trade volume in TON" + data_type: decimal(20,9) + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the trade was ingested" + data_type: timestamp + + - name: jetton_events + loaded_at_field: ingested_at + description: "TON jetton events" + columns: + - name: block_time + description: "Block timestamp" + data_type: timestamp + + - name: block_date + description: "Block date" + data_type: date + + - name: type + description: "Event type" + data_type: varchar + + - name: tx_hash + description: "Transaction hash" + data_type: varchar + + - name: tx_lt + description: "Transaction logical time" + data_type: bigint + + - name: utime + description: "Unix timestamp" + data_type: integer + + - name: trace_id + description: "Trace identifier" + data_type: varchar + + - name: tx_aborted + description: "Transaction aborted flag" + data_type: boolean + + - name: query_id + description: "Query identifier" + data_type: decimal(20,0) + + - name: amount + description: "Token amount" + data_type: decimal(38,0) + + - name: source + description: "Source address" + data_type: varchar + + - name: destination + description: "Destination address" + data_type: varchar + + - name: jetton_wallet + description: "Jetton wallet address" + data_type: varchar + + - name: jetton_master + description: "Jetton master contract address" + data_type: varchar + + - name: response_destination + description: "Response destination address" + data_type: varchar + + - name: custom_payload + description: "Custom payload data" + data_type: varbinary + + - name: forward_ton_amount + description: "Forward TON amount" + data_type: decimal(38,0) + + - name: forward_payload + description: "Forward payload data" + data_type: varbinary + + - name: comment + description: "Event comment" + data_type: varchar + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the event was ingested" + data_type: timestamp + + - name: jetton_metadata + loaded_at_field: ingested_at + description: "TON jetton metadata" + columns: + - name: address + description: "Jetton address" + data_type: varchar + + - name: update_time_onchain + description: "On-chain update timestamp" + data_type: integer + + - name: update_time_metadata + description: "Metadata update timestamp" + data_type: integer + + - name: mintable + description: "Mintable flag" + data_type: boolean + + - name: admin_address + description: "Admin address" + data_type: varchar + + - name: jetton_content_onchain + description: "On-chain jetton content" + data_type: varchar + + - name: jetton_wallet_code_hash + description: "Jetton wallet code hash" + data_type: varchar + + - name: code_hash + description: "Contract code hash" + data_type: varchar + + - name: metadata_status + description: "Metadata status" + data_type: integer + + - name: symbol + description: "Token symbol" + data_type: varchar + + - name: name + description: "Token name" + data_type: varchar + + - name: description + description: "Token description" + data_type: varchar + + - name: image + description: "Token image URL" + data_type: varchar + + - name: image_data + description: "Token image data" + data_type: varchar + + - name: decimals + description: "Token decimals" + data_type: integer + + - name: sources + description: "Original metadata sources" + data_type: row(symbol varchar, name varchar, description varchar, image varchar, image_data varchar, decimals varchar) + + - name: tonapi_image_url + description: "TON API image URL" + data_type: varchar + + - name: adding_date + description: "Token adding timestamp" + data_type: integer + + - name: updated_at + description: "Last update timestamp" + data_type: timestamp + + - name: ingested_at + description: "Time at which the metadata was ingested" + data_type: timestamp From d6ec34a35cd121cc7b7b7399e9aa6cb44b0d828b Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 20 Dec 2024 17:30:45 +0800 Subject: [PATCH 08/17] Fix bugs in sources (#7360) --- sources/_base_sources/{ => evm}/nova_base_sources.yml | 0 sources/_base_sources/other/ton_base_sources.yml | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename sources/_base_sources/{ => evm}/nova_base_sources.yml (100%) diff --git a/sources/_base_sources/nova_base_sources.yml b/sources/_base_sources/evm/nova_base_sources.yml similarity index 100% rename from sources/_base_sources/nova_base_sources.yml rename to sources/_base_sources/evm/nova_base_sources.yml diff --git a/sources/_base_sources/other/ton_base_sources.yml b/sources/_base_sources/other/ton_base_sources.yml index 55770d278b7..e63917e4c1b 100644 --- a/sources/_base_sources/other/ton_base_sources.yml +++ b/sources/_base_sources/other/ton_base_sources.yml @@ -13,13 +13,13 @@ sources: columns: - name: block_time description: "Block timestamp" - tests: + data_tests: - not_null data_type: timestamp - name: block_date description: "Block date" - tests: + data_tests: - not_null data_type: date From b40ad6dbb34820ea01d355ad2d9741c0bdd52820 Mon Sep 17 00:00:00 2001 From: bram-vdberg Date: Fri, 20 Dec 2024 11:29:56 +0100 Subject: [PATCH 09/17] Add new addresses for Portus (#7351) --- .../cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql | 2 ++ .../_project/cow_protocol/base/cow_protocol_base_solvers.sql | 2 ++ .../cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql | 1 + .../cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql | 2 ++ 4 files changed, 7 insertions(+) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql index cfda80c9661..b239d32644c 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql @@ -54,6 +54,8 @@ known_solver_metadata (address, environment, name) as ( (0x2692F7bFCB2e1a8575434b9511804266D9aeb628, 'prod', 'Velvet'), (0x0148538e6cA813D41eA5988008Cdc9B72d4e65A7, 'prod', 'Laita'), (0x1FA2FF499b327f53cD9a82BcAFE36093563E32e4, 'prod', 'Apollo'), + (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), + (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), (0x5E06F88D28603f5bB106bD5C8AD93ce2E902d24b, 'barn', 'Apollo'), (0x034F6Aca83F1900b0157b0123F514A29456eeA59, 'barn', 'Laita'), (0x669Be18D403Be353C1B9EBC87225313Ec2560BF5, 'barn', 'Velvet'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql index 70375160bd4..daeb2422c55 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql @@ -45,6 +45,8 @@ known_solver_metadata (address, environment, name) as ( (0x147d05987f3008A6C9Ec3E93A4ead430907ac3E1, 'barn', 'Gnosis_0x'), (0x9451D27C993f7a61096BFC33e0241644a7566F66, 'barn', 'Gnosis_BalancerSOR'), (0x0AC9287C83C2386A6a0bb27F847Ce59a0034183C, 'barn', 'Laita'), + (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), + (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), (0x69d7F96dFD091652f317D0734A5F2B492ACcbE07, 'prod', 'Baseline'), (0x4cb862E4821fea2dabBD1f0A69c17d52da2A58f6, 'prod', 'Seasolver'), (0xF401ceF222F1CA2fE84a8C7BFC75A636A4542A74, 'prod', 'Naive'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql index 1b598260e61..bb37674f4aa 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql @@ -119,6 +119,7 @@ known_solver_metadata (address, environment, name) as ( (0x95480d3f27658e73b2785d30beb0c847d78294c7, 'prod', 'Fractal'), (0x00806DaA2Cfe49715eA05243FF259DeB195760fC, 'prod', 'Quasilabs'), (0x28B1bd44996105b5c14c4dE41093226Ff78A4eB1, 'prod', '0x'), + (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), (0xcC73072B53697911Ff394ae01D3de59c9900b0b0, 'barn', '0x'), (0xd0bA1b1782fbdE45edAb392428f60e14827D08EC, 'barn', 'Laita'), (0x7E2eF26AdccB02e57258784957922AEEFEe807e5, 'barn', 'Quasilabs'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql index 3710ace1cd4..a68d5d4acd3 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/gnosis/cow_protocol_gnosis_solvers.sql @@ -65,6 +65,8 @@ known_solver_metadata (address, environment, name) as ( (0x53F5378A6f8bb24333aD8D68FD28816504a467b2, 'barn', 'Copium_Capital'), (0xC4dd6355Fbc6Eb108FD1C100389789C5B1A9A980, 'barn', 'Barter'), (0x4398129426Cb1377E9E10395b8dfBDa153c7Fe7D, 'barn', 'Fractal'), + (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), + (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), (0x727EB77c6f84ef148403f641aA32d75b7f6902A7, 'prod', 'Fractal'), (0x0a360134553feED49FE5eb273074d80B6e45941F, 'prod', 'Barter'), (0xb4694FE6590acd1281Dc34a966bbAE224559BaD4, 'prod', 'Copium_Capital'), From d7993856031d7c93e359eb0e04562f7680d31274 Mon Sep 17 00:00:00 2001 From: bram-vdberg Date: Fri, 20 Dec 2024 11:31:35 +0100 Subject: [PATCH 10/17] [CoW Protocol] Add Addresses for Laita, ApeOut 1Inch, and Project Blanc (#7346) * Add addresses for ApeOut 1Inch and Project Blanc * Add addresses for Laita solver --------- Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- .../cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql | 2 ++ .../_project/cow_protocol/base/cow_protocol_base_solvers.sql | 2 ++ .../cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql index b239d32644c..b6f51bab053 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/arbitrum/cow_protocol_arbitrum_solvers.sql @@ -54,6 +54,8 @@ known_solver_metadata (address, environment, name) as ( (0x2692F7bFCB2e1a8575434b9511804266D9aeb628, 'prod', 'Velvet'), (0x0148538e6cA813D41eA5988008Cdc9B72d4e65A7, 'prod', 'Laita'), (0x1FA2FF499b327f53cD9a82BcAFE36093563E32e4, 'prod', 'Apollo'), + (0x0148538e6cA813D41eA5988008Cdc9B72d4e65A7, 'prod', 'Laita'), + (0x034F6Aca83F1900b0157b0123F514A29456eeA59, 'barn', 'Laita'), (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), (0x5E06F88D28603f5bB106bD5C8AD93ce2E902d24b, 'barn', 'Apollo'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql index daeb2422c55..a3eb28bc6f6 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/base/cow_protocol_base_solvers.sql @@ -45,7 +45,9 @@ known_solver_metadata (address, environment, name) as ( (0x147d05987f3008A6C9Ec3E93A4ead430907ac3E1, 'barn', 'Gnosis_0x'), (0x9451D27C993f7a61096BFC33e0241644a7566F66, 'barn', 'Gnosis_BalancerSOR'), (0x0AC9287C83C2386A6a0bb27F847Ce59a0034183C, 'barn', 'Laita'), + (0x172FaCC5d970df43462b0f3aDe670d8cB86DC816, 'barn', 'ApeOut_1Inch'), (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), + (0x1a72876ebE781E42aB2Ee4278B539688D8B80E2D, 'prod', 'ApeOut_1Inch'), (0x6bf97aFe2D2C790999cDEd2a8523009eB8a0823f, 'prod', 'Portus'), (0x69d7F96dFD091652f317D0734A5F2B492ACcbE07, 'prod', 'Baseline'), (0x4cb862E4821fea2dabBD1f0A69c17d52da2A58f6, 'prod', 'Seasolver'), diff --git a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql index bb37674f4aa..5f9bc304b90 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/cow_protocol/ethereum/cow_protocol_ethereum_solvers.sql @@ -119,6 +119,11 @@ known_solver_metadata (address, environment, name) as ( (0x95480d3f27658e73b2785d30beb0c847d78294c7, 'prod', 'Fractal'), (0x00806DaA2Cfe49715eA05243FF259DeB195760fC, 'prod', 'Quasilabs'), (0x28B1bd44996105b5c14c4dE41093226Ff78A4eB1, 'prod', '0x'), + (0x04B89dBce06e7Aa2F4BBA78969ADD4576eB94788, 'prod', 'ApeOut_1Inch'), + (0xbada5552a3e5e2fb57db982e29257821a2cf192d, 'prod', 'Project_Blanc'), + (0x34717040928D7fd8154d4612f3228EFf14521023, 'prod', 'Laita'), + (0xBab555BaBEe5d867983902bC8db8F707157245Be, 'barn', 'Project_Blanc'), + (0x854490ef1d402D4f6fce05aBefE1C676eB0DCD74, 'barn', 'ApeOut_1Inch'), (0xBB765c920f86e2A2654c4B82deB5BC2E092fF93b, 'barn', 'Portus'), (0xcC73072B53697911Ff394ae01D3de59c9900b0b0, 'barn', '0x'), (0xd0bA1b1782fbdE45edAb392428f60e14827D08EC, 'barn', 'Laita'), From 8843bf1c2b7fd4e5d3846581b4e03dc3662675b7 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:39:59 +0000 Subject: [PATCH 11/17] Add balancer_cowswap_amm spells on Base (DEX) (#7357) * add balancer_cowswap_amm dex spells on base * update sources * fix copypasta --- .../balancer_cowswap_amm/_schema.yml | 8 +- .../balancer_cowswap_amm_trades.sql | 1 + .../balancer_cowswap_amm/base/_schema.yml | 137 ++++++++++++++++++ .../base/balancer_cowswap_amm_base_trades.sql | 74 ++++++++++ ...labels_balancer_cowswap_amm_pools_base.sql | 70 +++++++++ .../labels_balancer_cowswap_amm_pools.sql | 1 + sources/_subprojects_outputs/dex/_sources.yml | 2 + .../balancer_cowswap_amm/base/_sources.yml | 9 ++ 8 files changed, 298 insertions(+), 4 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/_schema.yml create mode 100644 dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/balancer_cowswap_amm_base_trades.sql create mode 100644 dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/labels_balancer_cowswap_amm_pools_base.sql create mode 100644 sources/balancer_cowswap_amm/base/_sources.yml diff --git a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/_schema.yml b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/_schema.yml index 00c2c437fdd..cb5cf106587 100644 --- a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/_schema.yml @@ -3,12 +3,12 @@ version: 2 models: - name: balancer_cowswap_amm_trades meta: - blockchain: arbitrum, ethereum, gnosis + blockchain: arbitrum, base, ethereum, gnosis sector: trades project: balancer_cowswap_amm contributors: viniabussafi config: - tags: ['balancer', 'cowswap', 'ethereum', 'gnosis', 'amm', 'trades'] + tags: ['balancer', 'cowswap', 'arbitrum', 'base', 'ethereum', 'gnosis', 'amm', 'trades'] description: "Trades on Balancer CoWSwap AMM pools" columns: - &blockchain @@ -89,12 +89,12 @@ models: - name: labels_balancer_cowswap_amm_pools meta: - blockchain: arbitrum, ethereum, gnosis + blockchain: arbitrum, base, ethereum, gnosis sector: labels project: balancer_cowswap_amm contributors: viniabussafi config: - tags: ['labels', 'ethereum', 'gnosis', 'balancer', 'pools'] + tags: ['labels', 'arbitrum', 'base', 'ethereum', 'gnosis', 'balancer', 'pools'] description: "Balancer CoWSwap AMM liquidity pools created on Ethereum." columns: - *blockchain diff --git a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/balancer_cowswap_amm_trades.sql b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/balancer_cowswap_amm_trades.sql index 4f0799af9a2..9a40561f718 100644 --- a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/balancer_cowswap_amm_trades.sql +++ b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/balancer_cowswap_amm_trades.sql @@ -8,6 +8,7 @@ {% set b_cow_amm_models = [ ref('balancer_cowswap_amm_arbitrum_trades'), + ref('balancer_cowswap_amm_base_trades'), ref('balancer_cowswap_amm_ethereum_trades'), ref('balancer_cowswap_amm_gnosis_trades') ] %} diff --git a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/_schema.yml b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/_schema.yml new file mode 100644 index 00000000000..9bab1c37503 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/_schema.yml @@ -0,0 +1,137 @@ +version: 2 + +models: + - name: balancer_cowswap_amm_base_trades + meta: + blockchain: base + sector: trades + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['balancer', 'cowswap', 'base', 'amm', 'trades'] + description: "Trades on Balancer CoWSwap AMM pools" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + columns: + - &blockchain + name: blockchain + description: "Blockchain" + - &project + name: project + description: "Project name (balancer)" + - &version + name: version + description: "Version of the project" + - &block_month + name: block_month + description: "Block month in UTC" + - &block_date + name: block_date + description: "Block date in UTC" + - &block_time + name: block_time + description: 'Block time in UTC' + - &block_number + name: block_number + description: 'Block number' + - &token_bought_symbol + name: token_bought_symbol + description: "Token symbol for token bought in the trade" + - &token_sold_symbol + name: token_sold_symbol + description: "Token symbol for token sold in the trade" + - &token_pair + name: token_pair + description: "Token symbol pair for each token involved in the trade" + - &token_bought_amount + name: token_bought_amount + description: "Value of the token bought at time of execution in the original currency" + - &token_sold_amount + name: token_sold_amount + description: "Value of the token sold at time of execution in the original currency" + - &token_bought_amount_raw + name: token_bought_amount_raw + description: "Raw value of the token bought at time of execution in the original currency" + - &token_sold_amount_raw + name: token_sold_amount_raw + description: "Raw value of the token sold at time of execution in the original currency" + - &amount_usd + name: amount_usd + description: "USD value of the trade at time of execution" + - &token_bought_address + name: token_bought_address + description: "Contract address of the token bought" + - &token_sold_address + name: token_sold_address + description: "Contract address of the token sold" + - &taker + name: taker + description: "Address of trader who purchased a token" + - &maker + name: maker + description: "Address of trader who sold a token" + - &project_contract_address + name: project_contract_address + description: "Pool address" + - &tx_hash + name: tx_hash + description: "Tx. Hash" + - &tx_from + name: tx_from + description: "transaction.from" + - &tx_to + name: tx_to + description: "transaction.to" + - &evt_index + name: evt_index + description: 'Event index' + - name: pool_type + - name: pool_symbol + - name: swap_fee + + - name: labels_balancer_cowswap_amm_pools_base + meta: + blockchain: base + sector: labels + project: balancer_cowswap_amm + contributors: viniabussafi + config: + tags: ['labels', 'base', 'balancer', 'pools'] + description: "Balancer CoWSwap AMM liquidity pools created on base." + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address + columns: + - *blockchain + - &address + name: address + description: "Address of liquidity pool" + - &name + name: name + description: "Label name of pool containing the token symbols and their respective weights (if applicable)" + - name: pool_type + - &category + name: category + description: "Label category" + - &contributor + name: contributor + description: "Wizard(s) contributing to labels" + - &source + name: source + description: "How were labels generated (could be static or query)" + - &created_at + name: created_at + description: "When were labels created" + - &updated_at + name: updated_at + description: "When were labels updated for the last time" + - &model_name + name: model_name + description: "Name of the label model sourced from" + - &label_type + name: label_type + description: "Type of label (see labels overall readme)" \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/balancer_cowswap_amm_base_trades.sql b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/balancer_cowswap_amm_base_trades.sql new file mode 100644 index 00000000000..91789f13833 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/balancer_cowswap_amm_base_trades.sql @@ -0,0 +1,74 @@ +{% set blockchain = 'base' %} + +{{ + config( + schema = 'balancer_cowswap_amm_' + blockchain, + alias = 'trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'evt_index'] + ) +}} + + SELECT + '{{blockchain}}' AS blockchain + , 'balancer' AS project + , '1' AS version + , CAST(date_trunc('month', trade.evt_block_time) AS DATE) AS block_month + , CAST(date_trunc('day', trade.evt_block_time) AS DATE) AS block_date + , trade.evt_block_time AS block_time + , trade.evt_block_number block_number + , tb.symbol AS token_bought_symbol + , ts.symbol AS token_sold_symbol + , CONCAT(ts.symbol, '-', tb.symbol) AS token_pair + , (trade.buyAmount / POWER(10, COALESCE(pb.decimals, tb.decimals))) AS token_bought_amount + , ((trade.sellAmount - trade.feeAmount) / POWER(10, COALESCE(ps.decimals, ts.decimals))) AS token_sold_amount + , trade.buyAmount AS token_bought_amount_raw + , trade.sellAmount AS token_sold_amount_raw + , COALESCE(trade.buyAmount / POWER(10, COALESCE(pb.decimals, tb.decimals)) * pb.price, + trade.sellAmount / POWER(10, COALESCE(ps.decimals, ts.decimals)) * ps.price) + AS amount_usd + ,trade.buyToken AS token_bought_address + ,trade.sellToken AS token_sold_address + ,CAST(NULL AS VARBINARY) AS taker + ,CAST(NULL AS VARBINARY) AS maker + , pool.bPool AS pool_id + , pool.bPool AS project_contract_address + , trade.evt_tx_hash AS tx_hash + , settlement.solver AS tx_from + , trade.contract_address AS tx_to + , trade.evt_index AS evt_index + , p.name AS pool_symbol + , p.pool_type + , (trade.feeAmount / POWER (10, ts.decimals)) AS swap_fee + FROM {{ source('gnosis_protocol_v2_base', 'GPv2Settlement_evt_Trade') }} trade + INNER JOIN {{ source('b_cow_amm_base', 'BCoWFactory_evt_LOG_NEW_POOL') }} pool + ON trade.owner = pool.bPool + LEFT JOIN {{ source('prices', 'usd') }} AS ps + ON sellToken = ps.contract_address + AND ps.minute = date_trunc('minute', trade.evt_block_time) + AND ps.blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('ps.minute') }} + {% endif %} + LEFT JOIN {{ source('prices', 'usd') }} AS pb + ON pb.contract_address = buyToken + AND pb.minute = date_trunc('minute', trade.evt_block_time) + AND pb.blockchain = '{{blockchain}}' + {% if is_incremental() %} + AND {{ incremental_predicate('pb.minute') }} + {% endif %} + LEFT JOIN {{ source('tokens', 'erc20') }} AS ts + ON trade.sellToken = ts.contract_address + AND ts.blockchain = '{{blockchain}}' + LEFT JOIN {{ source('tokens', 'erc20') }} AS tb + ON trade.buyToken = tb.contract_address + AND tb.blockchain = '{{blockchain}}' + LEFT JOIN {{ source('gnosis_protocol_v2_base', 'GPv2Settlement_evt_Settlement') }} AS settlement + ON trade.evt_tx_hash = settlement.evt_tx_hash + LEFT JOIN {{ ref('labels_balancer_cowswap_amm_pools_base') }} p ON p.address = trade.owner + {% if is_incremental() %} + WHERE {{ incremental_predicate('trade.evt_block_time') }} + {% endif %} diff --git a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/labels_balancer_cowswap_amm_pools_base.sql b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/labels_balancer_cowswap_amm_pools_base.sql new file mode 100644 index 00000000000..61c2076dac4 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/base/labels_balancer_cowswap_amm_pools_base.sql @@ -0,0 +1,70 @@ +{% set blockchain = 'base' %} + +{{config( + schema = 'labels', + alias = 'balancer_cowswap_amm_pools_' + blockchain, + materialized = 'table', + file_format = 'delta' + ) +}} + +WITH events AS ( + -- binds + SELECT call_block_number AS block_number, + contract_address AS pool, + token, + denorm + FROM {{ source('b_cow_amm_base', 'BCoWPool_call_bind') }} + WHERE call_success + + UNION all + + -- unbinds + SELECT call_block_number AS block_number, + contract_address AS pool, + token, + uint256 '0' AS denorm + FROM {{ source('b_cow_amm_base', 'BCoWPool_call_unbind') }} + WHERE call_success +), + +state_with_gaps AS ( + SELECT events.block_number + , events.pool + , events.token + , CAST(events.denorm AS uint256) AS denorm, + LEAD(events.block_number, 1, 99999999) OVER (PARTITION BY events.pool, events.token ORDER BY events.block_number) AS next_block_number + FROM events +), + +settings AS ( + SELECT pool, + coalesce(t.symbol,'?') AS symbol, + denorm, + next_block_number + FROM state_with_gaps s + LEFT JOIN {{ source('tokens', 'erc20') }} t ON s.token = t.contract_address + AND t.blockchain = '{{blockchain}}' + WHERE next_block_number = 99999999 + AND denorm > uint256 '0' +) + + SELECT + '{{blockchain}}' AS blockchain, + pool AS address, + CONCAT('BCowAMM: ', array_join(array_agg(symbol), '/'), ' ', array_join(array_agg(cast(norm_weight AS varchar)), '/')) AS name, + 'Balancer CoWSwap AMM' AS pool_type, + 'balancer_cowswap_amm_pool' AS category, + 'balancerlabs' AS contributor, + 'query' AS source, + timestamp '2024-07-20' AS created_at, + now() AS updated_at, + 'balancer_cowswap_amm_pools_base' AS model_name, + 'identifier' as label_type + FROM ( + SELECT s1.pool, symbol, cast(100*denorm/total_denorm AS integer) AS norm_weight FROM settings s1 + INNER JOIN (SELECT pool, sum(denorm) AS total_denorm FROM settings GROUP BY pool) s2 + ON s1.pool = s2.pool + ORDER BY 1 ASC , 3 DESC, 2 ASC + ) s + GROUP BY 1, 2 \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/labels_balancer_cowswap_amm_pools.sql b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/labels_balancer_cowswap_amm_pools.sql index c4032bb58a7..35dfe348fb2 100644 --- a/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/labels_balancer_cowswap_amm_pools.sql +++ b/dbt_subprojects/dex/models/_projects/balancer_cowswap_amm/labels_balancer_cowswap_amm_pools.sql @@ -7,6 +7,7 @@ {% set b_cow_amm_models = [ ref('labels_balancer_cowswap_amm_pools_arbitrum'), + ref('labels_balancer_cowswap_amm_pools_base'), ref('labels_balancer_cowswap_amm_pools_ethereum'), ref('labels_balancer_cowswap_amm_pools_gnosis') ] %} diff --git a/sources/_subprojects_outputs/dex/_sources.yml b/sources/_subprojects_outputs/dex/_sources.yml index c99a0f0dd97..1d1d25769a6 100644 --- a/sources/_subprojects_outputs/dex/_sources.yml +++ b/sources/_subprojects_outputs/dex/_sources.yml @@ -65,6 +65,8 @@ sources: - name: balancer_cowswap_amm_pools - name: balancer_v3_pools_ethereum - name: balancer_v3_pools_gnosis + - name: balancer_v3_pools_base + - name: balancer_v3_pools_arbitrum - name: balancer_v3_pools - name: uniswap_v3_optimism tables: diff --git a/sources/balancer_cowswap_amm/base/_sources.yml b/sources/balancer_cowswap_amm/base/_sources.yml new file mode 100644 index 00000000000..a122c59a6ca --- /dev/null +++ b/sources/balancer_cowswap_amm/base/_sources.yml @@ -0,0 +1,9 @@ +version: 2 +sources: + - name: b_cow_amm_base + tables: + - name: BCoWFactory_evt_LOG_NEW_POOL + - name: BCoWFactory_evt_COWAMMPoolCreated + - name: BCoWFactory_call_logBCoWPool + - name: BCoWPool_call_bind + - name: BCoWPool_call_unbind \ No newline at end of file From 9c81e911b0e5458fe7b7fcf1e092f508abc001a3 Mon Sep 17 00:00:00 2001 From: whale_hunter <143016036+whalehunting@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:40:26 +0100 Subject: [PATCH 12/17] chore: add additional aggregator fee wallets for flokibot (#7343) * chore-add-additional-openocean-fee-wallet-for-flokibot * fix: add missing referrer * chore: use same fee wallets across all custom routers + aggregators * fix: remove duplicated source --------- Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- .../base/flokibot_base_bot_trades.sql | 19 +++++++++++++++++++ .../flokibot/bnb/flokibot_bnb_bot_trades.sql | 12 ++++++++++-- .../ethereum/flokibot_ethereum_bot_trades.sql | 8 +++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql index 6414dedc79d..dbdbdc01f5d 100644 --- a/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql +++ b/dbt_subprojects/dex/models/bot_trades/flokibot/base/flokibot_base_bot_trades.sql @@ -40,6 +40,7 @@ with ( to = {{ treasury_fee_wallet_1 }} or to = {{ treasury_fee_wallet_2 }} + or to = {{ aggregator_fee_wallet_1 }} or to = {{ buyback_fee_wallet_1 }} ) and tx_success = true @@ -56,7 +57,9 @@ with where ( varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_1 }}) > 0 or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0 + or varbinary_position(data, {{ buyback_fee_wallet_1 }}) > 0 ) and call_success {% if is_incremental() %} @@ -64,12 +67,28 @@ with {% else %} and call_block_time >= timestamp '{{project_start_date}}' {% endif %} ), + openocean_aggregator_trades as ( + select evt_block_time as block_time, evt_tx_hash as tx_hash + from {{ source('openocean_v2_base', 'OpenOceanExchange_evt_Swapped') }} + where + referrer = {{ aggregator_fee_wallet_1 }} + or referrer = {{ treasury_fee_wallet_1 }} + or referrer = {{ treasury_fee_wallet_2 }} + or referrer = {{ buyback_fee_wallet_1 }} + {% if is_incremental() %} + and {{ incremental_predicate('evt_block_time') }} + {% else %} and evt_block_time >= timestamp '{{project_start_date}}' + {% endif %} + ), trade_transactions as ( select block_time, address, null as tx_hash from bot_contracts union all select block_time, null as address, tx_hash from oneinch_aggregator_trades + union all + select block_time, null as address, tx_hash + from openocean_aggregator_trades ), bot_trades as ( select diff --git a/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql index 63eade0c94a..0ae3261690a 100644 --- a/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql +++ b/dbt_subprojects/dex/models/bot_trades/flokibot/bnb/flokibot_bnb_bot_trades.sql @@ -40,8 +40,10 @@ with from {{ source('bnb', 'traces') }} where ( - to = {{ treasury_fee_wallet_1 }} + to = {{ aggregator_fee_wallet_1 }} + or to = {{ treasury_fee_wallet_1 }} or to = {{ treasury_fee_wallet_2 }} + or to = {{ treasury_fee_wallet_3 }} or to = {{ buyback_fee_wallet_1 }} ) and tx_success = true @@ -58,8 +60,10 @@ with where ( varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_1 }}) > 0 or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0 or varbinary_position(data, {{ treasury_fee_wallet_3 }}) > 0 + or varbinary_position(data, {{ buyback_fee_wallet_1 }}) > 0 ) and call_success {% if is_incremental() %} @@ -71,7 +75,11 @@ with select evt_block_time as block_time, evt_tx_hash as tx_hash from {{ source('openocean_v2_bnb', 'OpenOceanExchange_evt_Swapped') }} where - referrer = {{ treasury_fee_wallet_3 }} + referrer = {{ aggregator_fee_wallet_1 }} + OR referrer = {{ treasury_fee_wallet_1 }} + OR referrer = {{ treasury_fee_wallet_2 }} + OR referrer = {{ treasury_fee_wallet_3 }} + OR referrer = {{ buyback_fee_wallet_1 }} {% if is_incremental() %} and {{ incremental_predicate('evt_block_time') }} {% else %} and evt_block_time >= timestamp '{{project_start_date}}' diff --git a/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql b/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql index 767d546a6c9..65b05a754c4 100644 --- a/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql +++ b/dbt_subprojects/dex/models/bot_trades/flokibot/ethereum/flokibot_ethereum_bot_trades.sql @@ -40,6 +40,7 @@ with ( to = {{ treasury_fee_wallet_1 }} or to = {{ treasury_fee_wallet_2 }} + or to = {{ aggregator_fee_wallet_1 }} or to = {{ buyback_fee_wallet_1 }} ) and tx_success = true @@ -56,7 +57,9 @@ with where ( varbinary_position(data, {{ aggregator_fee_wallet_1 }}) > 0 + or varbinary_position(data, {{ treasury_fee_wallet_1 }}) > 0 or varbinary_position(data, {{ treasury_fee_wallet_2 }}) > 0 + or varbinary_position(data, {{ buyback_fee_wallet_1 }}) > 0 ) and call_success {% if is_incremental() %} @@ -68,7 +71,10 @@ with select evt_block_time as block_time, evt_tx_hash as tx_hash from {{ source('openocean_v2_ethereum', 'OpenOceanExchangeProxy_evt_Swapped') }} where - referrer = {{ treasury_fee_wallet_2 }} + referrer = {{ treasury_fee_wallet_1 }} + or referrer = {{ treasury_fee_wallet_2 }} + or referrer = {{ aggregator_fee_wallet_1 }} + or referrer = {{ buyback_fee_wallet_1 }} {% if is_incremental() %} and {{ incremental_predicate('evt_block_time') }} {% else %} and evt_block_time >= timestamp '{{project_start_date}}' From b272595727ad1242e1c324b1d9005799f183ffa3 Mon Sep 17 00:00:00 2001 From: blanchemaria6 <130497866+blanchemaria6@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:40:33 +0700 Subject: [PATCH 13/17] Update dex.trades with Gravity finance (#7324) * Update dex_info.sql * Update _schema.yml * Update dex_polygon_base_trades.sql * Create gravity_finance_polygon_base_trades.sql * Update _schema.yml * Create gravity_finance_polygon_base_trades_seed.csv * Update _sources.yml * Update gravity_finance_polygon_base_trades_seed.csv * Update gravity_finance_polygon_base_trades_seed.csv * Update dbt_subprojects/dex/models/trades/polygon/_schema.yml Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/polygon/_schema.yml | 18 +++++++++++++++- .../polygon/dex_polygon_base_trades.sql | 1 + .../gravity_finance_polygon_base_trades.sql | 21 +++++++++++++++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 15 +++++++++++++ ...avity_finance_polygon_base_trades_seed.csv | 2 ++ .../_sector/dex/trades/polygon/_sources.yml | 4 ++++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 dbt_subprojects/dex/models/trades/polygon/platforms/gravity_finance_polygon_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/gravity_finance_polygon_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index 678dbf2100d..227b69ce997 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -192,5 +192,6 @@ FROM (VALUES , ('katana', 'Katana', 'Direct', 'AxieInfinity') , ('jetswap', 'JetSwap', 'Direct', 'Jetfuelfinance') , ('levinswap', 'Levinswap', 'Direct', 'levinswap') + , ('gravity_finance', 'GravityFinance', 'Direct', 'Gravity_Finance') , ('fluid', 'Fluid DEX', 'Direct', '0xfluid') ) AS temp_table (project, name, marketplace_type, x_username) diff --git a/dbt_subprojects/dex/models/trades/polygon/_schema.yml b/dbt_subprojects/dex/models/trades/polygon/_schema.yml index ede80f4ae2f..f96740412f2 100644 --- a/dbt_subprojects/dex/models/trades/polygon/_schema.yml +++ b/dbt_subprojects/dex/models/trades/polygon/_schema.yml @@ -413,4 +413,20 @@ models: - evt_index - check_dex_base_trades_seed: seed_file: ref('jetswap_polygon_base_trades_seed') - + + - name: gravity_finance_polygon_base_trades + meta: + blockchain: polygon + sector: dex + project: gravity_finance + contributors: blanchemaria6 + config: + tags: [ 'polygon', 'dex', 'trades', 'gravity_finance' ] + description: "gravity_finance polygon base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('gravity_finance_polygon_base_trades_seed') diff --git a/dbt_subprojects/dex/models/trades/polygon/dex_polygon_base_trades.sql b/dbt_subprojects/dex/models/trades/polygon/dex_polygon_base_trades.sql index 2a324993760..dfd6b528df3 100644 --- a/dbt_subprojects/dex/models/trades/polygon/dex_polygon_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/polygon/dex_polygon_base_trades.sql @@ -27,6 +27,7 @@ , ref('swaap_v2_polygon_base_trades') , ref('dfyn_polygon_base_trades') , ref('jetswap_polygon_base_trades') + , ref('gravity_finance_polygon_base_trades') ] %} WITH base_union AS ( diff --git a/dbt_subprojects/dex/models/trades/polygon/platforms/gravity_finance_polygon_base_trades.sql b/dbt_subprojects/dex/models/trades/polygon/platforms/gravity_finance_polygon_base_trades.sql new file mode 100644 index 00000000000..618310ae78d --- /dev/null +++ b/dbt_subprojects/dex/models/trades/polygon/platforms/gravity_finance_polygon_base_trades.sql @@ -0,0 +1,21 @@ +{{ + config( + schema = 'gravity_finance_polygon', + alias = 'base_trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +{{ + uniswap_compatible_v2_trades( + blockchain = 'polygon', + project = 'gravity_finance', + version = '1', + Pair_evt_Swap = source('gravity_finance_polygon', 'UniswapV2Pair_evt_Swap'), + Factory_evt_PairCreated = source('gravity_finance_polygon', 'UniswapV2Factory_evt_PairCreated') + ) +}} diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index 1bc3dd58d97..49f1c1e84a1 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -4574,6 +4574,21 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp + + - name: gravity_finance_polygon_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp - name: fluid_ethereum_base_trades_seed config: diff --git a/dbt_subprojects/dex/seeds/trades/gravity_finance_polygon_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/gravity_finance_polygon_base_trades_seed.csv new file mode 100644 index 00000000000..56ffaf7b480 --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/gravity_finance_polygon_base_trades_seed.csv @@ -0,0 +1,2 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw +polygon,gravity_finance,1,2024-11-17,0x83a1ea6fefce0f22da8a3afb07268ef334d32a46c32040c9f67882b781749057,587,0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6,0x03b54a6e9a984069379fae1a4fc4dbae93b3bccd,64393636,881,216474154607113 diff --git a/sources/_sector/dex/trades/polygon/_sources.yml b/sources/_sector/dex/trades/polygon/_sources.yml index 1c1a1ddd394..0f1a0e5624e 100644 --- a/sources/_sector/dex/trades/polygon/_sources.yml +++ b/sources/_sector/dex/trades/polygon/_sources.yml @@ -79,3 +79,7 @@ sources: tables: - name: JetswapPair_evt_Swap - name: JetswapFactory_evt_PairCreated + - name: gravity_finance_polygon + tables: + - name: UniswapV2Pair_evt_Swap + - name: UniswapV2Factory_evt_PairCreated From 444fd27a32d66a359a96bd741af5e0c76909b046 Mon Sep 17 00:00:00 2001 From: Patel Princi Date: Fri, 20 Dec 2024 16:10:45 +0530 Subject: [PATCH 14/17] Saddle Finance DEX on Optimism Chain (#7282) * Saddle file added in sql * files added for saddle finance * removed filter version and some of the unwanted unique keys --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/optimism/_schema.yml | 17 +++++++ .../optimism/dex_optimism_base_trades.sql | 1 + .../saddle_finance_optimism_base_trades.sql | 50 +++++++++++++++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 15 ++++++ ...ddle_finance_optimism_base_trades_seed.csv | 2 + .../_sector/dex/trades/optimism/_sources.yml | 3 ++ 7 files changed, 89 insertions(+) create mode 100644 dbt_subprojects/dex/models/trades/optimism/platforms/saddle_finance_optimism_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/saddle_finance_optimism_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index 227b69ce997..ef08d06f0b5 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -189,6 +189,7 @@ FROM (VALUES , ('stablebase', 'StableBase', 'Direct', 'stablebasefi') , ('flashliquidity', 'Flashliquidity', 'Direct', 'flashliquidity') , ('akronswap', 'Akronswap', 'Direct', 'AkronFinance') + , ('saddle_finance', 'Saddle Finance', 'Direct', 'saddlefinance') , ('katana', 'Katana', 'Direct', 'AxieInfinity') , ('jetswap', 'JetSwap', 'Direct', 'Jetfuelfinance') , ('levinswap', 'Levinswap', 'Direct', 'levinswap') diff --git a/dbt_subprojects/dex/models/trades/optimism/_schema.yml b/dbt_subprojects/dex/models/trades/optimism/_schema.yml index 031f300b0dc..95626994551 100644 --- a/dbt_subprojects/dex/models/trades/optimism/_schema.yml +++ b/dbt_subprojects/dex/models/trades/optimism/_schema.yml @@ -568,3 +568,20 @@ models: seed_file: ref('swaap_optimism_base_trades_seed') filter: version: 2 + + - name: saddle_finance_optimism_base_trades + meta: + blockchain: optimism + sector: dex + project: saddle_finance + contributors: princi + config: + tags: [ 'optimism', 'dex', 'trades', 'saddle_finance'] + description: "saddle finance optimism base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('saddle_finance_optimism_base_trades_seed') diff --git a/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql b/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql index f81d356fac8..72bea48676f 100644 --- a/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql @@ -35,6 +35,7 @@ , ref('elk_finance_optimism_base_trades') , ref('fraxswap_optimism_base_trades') , ref('swaap_v2_optimism_base_trades') + , ref('saddle_finance_optimism_base_trades') ] %} WITH base_union AS ( diff --git a/dbt_subprojects/dex/models/trades/optimism/platforms/saddle_finance_optimism_base_trades.sql b/dbt_subprojects/dex/models/trades/optimism/platforms/saddle_finance_optimism_base_trades.sql new file mode 100644 index 00000000000..dda9f17a17e --- /dev/null +++ b/dbt_subprojects/dex/models/trades/optimism/platforms/saddle_finance_optimism_base_trades.sql @@ -0,0 +1,50 @@ +{{ config( + schema = 'saddle_finance_optimism', + alias = 'base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['tx_hash', 'evt_index'] +) }} + +WITH token_swaps AS ( + SELECT + evt_block_number AS block_number, + CAST(evt_block_time AS timestamp(3) with time zone) AS block_time, + evt_tx_from AS maker, + evt_tx_to AS taker, + tokensSold AS token_sold_amount_raw, + tokensBought AS token_bought_amount_raw, + CAST(soldId AS varbinary) AS token_sold_address, + CAST(boughtId AS varbinary) AS token_bought_address, + contract_address AS project_contract_address, + evt_tx_hash AS tx_hash, + evt_index AS evt_index + FROM + {{ source('saddle_finance_optimism', 'SwapFlashLoan_evt_TokenSwap') }} + {% if is_incremental() %} + WHERE + {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +SELECT + 'optimism' AS blockchain, + 'saddle_finance' AS project, + '1' AS version, + CAST(date_trunc('month', token_swaps.block_time) AS date) AS block_month, + CAST(date_trunc('day', token_swaps.block_time) AS date) AS block_date, + token_swaps.block_time, + token_swaps.block_number, + token_swaps.token_sold_amount_raw, + token_swaps.token_bought_amount_raw, + token_swaps.token_sold_address, + token_swaps.token_bought_address, + token_swaps.maker, + token_swaps.taker, + token_swaps.project_contract_address, + token_swaps.tx_hash, + token_swaps.evt_index +FROM + token_swaps diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index 49f1c1e84a1..da4c398563d 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -4499,6 +4499,21 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp + + - name: saddle_finance_optimism_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp - name: akronswap_base_base_trades_seed config: diff --git a/dbt_subprojects/dex/seeds/trades/saddle_finance_optimism_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/saddle_finance_optimism_base_trades_seed.csv new file mode 100644 index 00000000000..a459ed8b479 --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/saddle_finance_optimism_base_trades_seed.csv @@ -0,0 +1,2 @@ +blockchain,project,version,block_month,block_date,block_time,block_number,token_sold_amount_raw,token_bought_amount_raw,token_sold_address,token_bought_address,maker,taker,project_contract_address,tx_hash,evt_index +optimism,saddle_finance,1,2022-08-01 00:00,2022-08-05 00:00,2022-08-05 19:11,17943155,74907384,74857799085655995549,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000001,0xd131f1bcdd547e067af447dd3c36c99d6be9fdeb,0xf6c2e0adc659007ba7c48446f5a4e4e94dfe08b5,0xf6c2e0adc659007ba7c48446f5a4e4e94dfe08b5,0xbccdcd4ab61e5ad3384eb173156c3c0507d3bb3f2d2f5a406379e74aafbec38d,3 \ No newline at end of file diff --git a/sources/_sector/dex/trades/optimism/_sources.yml b/sources/_sector/dex/trades/optimism/_sources.yml index e13ce79639f..3aa47f8f5cf 100644 --- a/sources/_sector/dex/trades/optimism/_sources.yml +++ b/sources/_sector/dex/trades/optimism/_sources.yml @@ -95,3 +95,6 @@ sources: - name: swaap_v2_optimism tables: - name: Vault_evt_Swap + - name: saddle_finance_optimism + tables: + - name: SwapFlashLoan_evt_TokenSwap From c77a2bc7ed17bc26c3afc4c052175cf01efd4c99 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:41:14 +0000 Subject: [PATCH 15/17] enrich balancer_v3 trades on dex.trades (#7350) * enrich balancer_v3 trades * add missing ) * add missing quote * fix group by * again * alias blockchain * add date filter to decrease run time * add balancer trades to models * include bv2 --- .../models/enrich_balancer_v3_dex_trades.sql | 122 ++++++++++++++++++ dbt_subprojects/dex/models/trades/_schema.yml | 2 +- .../dex/models/trades/dex_trades.sql | 17 ++- 3 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 dbt_subprojects/dex/macros/models/enrich_balancer_v3_dex_trades.sql diff --git a/dbt_subprojects/dex/macros/models/enrich_balancer_v3_dex_trades.sql b/dbt_subprojects/dex/macros/models/enrich_balancer_v3_dex_trades.sql new file mode 100644 index 00000000000..094f4360d1a --- /dev/null +++ b/dbt_subprojects/dex/macros/models/enrich_balancer_v3_dex_trades.sql @@ -0,0 +1,122 @@ +{% macro enrich_balancer_v3_dex_trades( + base_trades = null + , filter = null + , tokens_erc20_model = null + ) +%} + +WITH base_trades as ( + SELECT + * + FROM + {{ base_trades }} + WHERE + {{ filter }} + {% if is_incremental() %} + AND + {{ incremental_predicate('block_time') }} + {% endif %} +) +, enrichments AS ( + SELECT + base_trades.blockchain + , base_trades.project + , base_trades.version + , base_trades.block_month + , base_trades.block_date + , base_trades.block_time + , base_trades.block_number + , erc20_bought.symbol AS token_bought_symbol + , erc20_sold.symbol AS token_sold_symbol + , CASE + WHEN lower(erc20_bought.symbol) > lower(erc20_sold.symbol) THEN concat(erc20_sold.symbol, '-', erc20_bought.symbol) + ELSE concat(erc20_bought.symbol, '-', erc20_sold.symbol) + END AS token_pair + , base_trades.token_bought_amount_raw / power(10, erc20_bought.decimals) AS token_bought_amount + , base_trades.token_sold_amount_raw / power(10, erc20_sold.decimals) AS token_sold_amount + , base_trades.token_bought_amount_raw + , base_trades.token_sold_amount_raw + , base_trades.token_bought_address + , base_trades.token_sold_address + , coalesce(base_trades.taker, base_trades.tx_from) AS taker + , base_trades.maker + , base_trades.project_contract_address + , base_trades.tx_hash + , base_trades.tx_from + , base_trades.tx_to + , base_trades.evt_index + FROM + base_trades + LEFT JOIN + {{ tokens_erc20_model }} as erc20_bought + ON erc20_bought.contract_address = base_trades.token_bought_address + AND erc20_bought.blockchain = base_trades.blockchain + LEFT JOIN + {{ tokens_erc20_model }} as erc20_sold + ON erc20_sold.contract_address = base_trades.token_sold_address + AND erc20_sold.blockchain = base_trades.blockchain +) + +, enrichments_with_prices AS ( + {{ + add_amount_usd( + trades_cte = 'enrichments' + ) + }} +) + +, erc4626_prices AS( + SELECT + minute, + blockchain, + wrapped_token, + decimals, + APPROX_PERCENTILE(median_price, 0.5) AS price, + LEAD(minute, 1, NOW()) OVER (PARTITION BY wrapped_token ORDER BY minute) AS time_of_next_change + FROM {{ source('balancer_v3', 'erc4626_token_prices') }} + GROUP BY 1, 2, 3, 4 +) + +SELECT + dexs.blockchain + , project + , version + , block_month + , block_date + , block_time + , block_number + , token_bought_symbol + , token_sold_symbol + , token_pair + , token_bought_amount + , token_sold_amount + , token_bought_amount_raw + , token_sold_amount_raw + , COALESCE( + dexs.amount_usd, + dexs.token_bought_amount * erc4626a.price, + dexs.token_sold_amount * erc4626a.price + ) AS amount_usd + , token_bought_address + , token_sold_address + , taker + , maker + , project_contract_address + , tx_hash + , tx_from + , tx_to + , evt_index +FROM + enrichments_with_prices dexs +LEFT JOIN erc4626_prices erc4626a + ON erc4626a.wrapped_token = dexs.token_bought_address + AND erc4626a.minute <= dexs.block_time + AND dexs.block_time < erc4626a.time_of_next_change + AND dexs.blockchain = erc4626a.blockchain +LEFT JOIN erc4626_prices erc4626b + ON erc4626b.wrapped_token = dexs.token_sold_address + AND erc4626b.minute <= dexs.block_time + AND dexs.block_time < erc4626b.time_of_next_change + AND dexs.blockchain = erc4626b.blockchain + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/trades/_schema.yml b/dbt_subprojects/dex/models/trades/_schema.yml index c913109f5c5..cb10cfb6b1d 100644 --- a/dbt_subprojects/dex/models/trades/_schema.yml +++ b/dbt_subprojects/dex/models/trades/_schema.yml @@ -7,7 +7,7 @@ models: blockchain: arbitrum, avalanche_c, base, bnb, celo, ethereum, fantom, gnosis, kaia, optimism, polygon, scroll, zksync, linea, blast, sei, ronin sector: dex short_description: The `dex.trades` table captures detailed data on trades executed via decentralized exchanges (DEXs). This table contains a detailed breakdown of trade execution containing one or many trades per transaction. - contributors: 0xRob, hosuke, jeff-dude, tomfutago + contributors: 0xRob, hosuke, jeff-dude, tomfutago, viniabussafi config: tags: [ 'dex', 'trades'] description: '{{ doc("dex_trades_doc") }}' diff --git a/dbt_subprojects/dex/models/trades/dex_trades.sql b/dbt_subprojects/dex/models/trades/dex_trades.sql index 654e2eb5e4a..ca7c8289878 100644 --- a/dbt_subprojects/dex/models/trades/dex_trades.sql +++ b/dbt_subprojects/dex/models/trades/dex_trades.sql @@ -32,7 +32,7 @@ ]\', "sector", "dex", - \'["hosuke", "0xrob", "jeff-dude", "tomfutago"]\') }}') + \'["hosuke", "0xrob", "jeff-dude", "tomfutago", "viniabussafi"]\') }}') }} -- keep existing dbt lineages for the following projects, as the team built themselves and use the spells throughout the entire lineage @@ -46,18 +46,28 @@ WITH curve AS ( {{ enrich_curve_dex_trades( base_trades = ref('dex_base_trades') - , filter = "project = 'curve'" + , filter = "project = 'curve' AND block_date = TIMESTAMP '2024-12-17'" , curve_ethereum = ref('curve_ethereum_base_trades') , curve_optimism = ref('curve_optimism_base_trades') , tokens_erc20_model = source('tokens', 'erc20') ) }} ) +, balancer_v3 AS ( + -- due to Balancer V3 having trades between ERC4626 tokens, which won't be priced on prices.usd, enrich separately + {{ + enrich_balancer_v3_dex_trades( + base_trades = ref('dex_base_trades') + , filter = "(project = 'balancer' AND version = '3') AND block_date = TIMESTAMP '2024-12-17'" + , tokens_erc20_model = source('tokens', 'erc20') + ) + }} +) , dexs AS ( {{ enrich_dex_trades( base_trades = ref('dex_base_trades') - , filter = "project != 'curve'" + , filter = "project != 'curve' AND NOT (project = 'balancer' AND version = '3') AND block_date = TIMESTAMP '2024-12-17'" , tokens_erc20_model = source('tokens', 'erc20') ) }} @@ -106,6 +116,7 @@ WITH curve AS ( 'curve' , 'as_is_dexs' , 'dexs' + , 'balancer_v3' ] %} From dd8fbf749d19b077bf101c584eeedeeb18a58b06 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Fri, 20 Dec 2024 12:41:37 +0200 Subject: [PATCH 16/17] New Event Models for GMX v2 (next iteration) (#7314) * Add 36 models and update schemas * Fix errors in 2 schemas * Added token contracts in 2 events * Added 2 new models * Replace UNION with UNION ALL * Added uniqueness tests --------- Co-authored-by: Huang Geyang Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> --- ...imable_funding_amount_per_size_updated.sql | 195 ++++ .../gmx_v2_arbitrum_deposit_cancelled.sql | 187 ++++ .../gmx_v2_arbitrum_deposit_created.sql | 258 +++++ .../gmx_v2_arbitrum_deposit_executed.sql | 199 ++++ .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 989 +++++++++++++++++- .../gmx_v2_arbitrum_execution_fee_refund.sql | 2 +- ...um_funding_fee_amount_per_size_updated.sql | 195 ++++ .../arbitrum/gmx_v2_arbitrum_glv_created.sql | 157 +++ .../gmx_v2_arbitrum_glv_deposit_cancelled.sql | 187 ++++ .../gmx_v2_arbitrum_glv_deposit_created.sql | 269 +++++ .../gmx_v2_arbitrum_glv_deposit_executed.sql | 186 ++++ .../gmx_v2_arbitrum_glv_shift_cancelled.sql | 167 +++ .../gmx_v2_arbitrum_glv_shift_created.sql | 200 ++++ .../gmx_v2_arbitrum_glv_shift_executed.sql | 165 +++ ...x_v2_arbitrum_glv_withdrawal_cancelled.sql | 187 ++++ ...gmx_v2_arbitrum_glv_withdrawal_created.sql | 255 +++++ ...mx_v2_arbitrum_glv_withdrawal_executed.sql | 149 +++ .../gmx_v2_arbitrum_keeper_execution_fee.sql | 2 +- .../gmx_v2_arbitrum_market_created.sql | 2 +- ...bitrum_open_interest_in_tokens_updated.sql | 2 +- .../gmx_v2_arbitrum_open_interest_updated.sql | 2 +- .../gmx_v2_arbitrum_oracle_price_update.sql | 2 +- .../gmx_v2_arbitrum_order_cancelled.sql | 2 +- .../gmx_v2_arbitrum_order_executed.sql | 2 +- .../arbitrum/gmx_v2_arbitrum_order_frozen.sql | 2 +- .../gmx_v2_arbitrum_pool_amount_updated.sql | 2 +- .../gmx_v2_arbitrum_position_decrease.sql | 2 +- ...mx_v2_arbitrum_position_fees_collected.sql | 2 +- .../gmx_v2_arbitrum_position_fees_info.sql | 2 +- .../gmx_v2_arbitrum_position_increase.sql | 2 +- .../arbitrum/gmx_v2_arbitrum_set_uint.sql | 2 +- .../gmx_v2_arbitrum_shift_created.sql | 218 ++++ .../gmx_v2_arbitrum_shift_executed.sql | 168 +++ .../gmx_v2_arbitrum_withdrawal_cancelled.sql | 187 ++++ .../gmx_v2_arbitrum_withdrawal_created.sql | 243 +++++ .../gmx_v2_arbitrum_withdrawal_executed.sql | 169 +++ ...imable_funding_amount_per_size_updated.sql | 195 ++++ .../gmx_v2_avalanche_c_deposit_cancelled.sql | 187 ++++ .../gmx_v2_avalanche_c_deposit_created.sql | 258 +++++ .../gmx_v2_avalanche_c_deposit_executed.sql | 199 ++++ .../gmx_v2_avalanche_c_event_schema.yml | 986 ++++++++++++++++- ...mx_v2_avalanche_c_execution_fee_refund.sql | 2 +- ..._c_funding_fee_amount_per_size_updated.sql | 195 ++++ .../gmx_v2_avalanche_c_glv_created.sql | 157 +++ ...x_v2_avalanche_c_glv_deposit_cancelled.sql | 187 ++++ ...gmx_v2_avalanche_c_glv_deposit_created.sql | 269 +++++ ...mx_v2_avalanche_c_glv_deposit_executed.sql | 186 ++++ ...gmx_v2_avalanche_c_glv_shift_cancelled.sql | 167 +++ .../gmx_v2_avalanche_c_glv_shift_created.sql | 200 ++++ .../gmx_v2_avalanche_c_glv_shift_executed.sql | 165 +++ ...2_avalanche_c_glv_withdrawal_cancelled.sql | 187 ++++ ..._v2_avalanche_c_glv_withdrawal_created.sql | 255 +++++ ...v2_avalanche_c_glv_withdrawal_executed.sql | 149 +++ ...mx_v2_avalanche_c_keeper_execution_fee.sql | 2 +- .../gmx_v2_avalanche_c_market_created.sql | 2 +- ...nche_c_open_interest_in_tokens_updated.sql | 2 +- ...x_v2_avalanche_c_open_interest_updated.sql | 2 +- ...gmx_v2_avalanche_c_oracle_price_update.sql | 2 +- .../gmx_v2_avalanche_c_order_cancelled.sql | 2 +- .../gmx_v2_avalanche_c_order_executed.sql | 2 +- .../gmx_v2_avalanche_c_order_frozen.sql | 2 +- ...gmx_v2_avalanche_c_pool_amount_updated.sql | 2 +- .../gmx_v2_avalanche_c_position_decrease.sql | 2 +- ...v2_avalanche_c_position_fees_collected.sql | 2 +- .../gmx_v2_avalanche_c_position_fees_info.sql | 2 +- .../gmx_v2_avalanche_c_position_increase.sql | 2 +- .../gmx_v2_avalanche_c_set_uint.sql | 2 +- .../gmx_v2_avalanche_c_shift_created.sql | 218 ++++ .../gmx_v2_avalanche_c_shift_executed.sql | 168 +++ ...mx_v2_avalanche_c_withdrawal_cancelled.sql | 187 ++++ .../gmx_v2_avalanche_c_withdrawal_created.sql | 243 +++++ ...gmx_v2_avalanche_c_withdrawal_executed.sql | 169 +++ ...imable_funding_amount_per_size_updated.sql | 41 + .../gmx/event/gmx_v2_deposit_cancelled.sql | 39 + .../gmx/event/gmx_v2_deposit_created.sql | 51 + .../gmx/event/gmx_v2_deposit_executed.sql | 43 + .../gmx/event/gmx_v2_event_schema.yml | 905 +++++++++++++++- ...v2_funding_fee_amount_per_size_updated.sql | 40 + .../gmx/event/gmx_v2_glv_created.sql | 44 + .../event/gmx_v2_glv_deposit_cancelled.sql | 42 + .../gmx/event/gmx_v2_glv_deposit_created.sql | 56 + .../gmx/event/gmx_v2_glv_deposit_executed.sql | 42 + .../gmx/event/gmx_v2_glv_shift_cancelled.sql | 41 + .../gmx/event/gmx_v2_glv_shift_created.sql | 44 + .../gmx/event/gmx_v2_glv_shift_executed.sql | 39 + .../event/gmx_v2_glv_withdrawal_cancelled.sql | 42 + .../event/gmx_v2_glv_withdrawal_created.sql | 52 + .../event/gmx_v2_glv_withdrawal_executed.sql | 40 + .../gmx/event/gmx_v2_shift_created.sql | 49 + .../gmx/event/gmx_v2_shift_executed.sql | 41 + .../gmx/event/gmx_v2_withdrawal_cancelled.sql | 41 + .../gmx/event/gmx_v2_withdrawal_created.sql | 49 + .../gmx/event/gmx_v2_withdrawal_executed.sql | 40 + .../gmx_v2_arbitrum_glv_markets_data.sql | 24 + .../arbitrum/gmx_v2_arbitrum_markets_data.sql | 3 + .../gmx_v2_arbitrum_tokens_schema.yml | 44 +- .../gmx_v2_avalanche_c_glv_markets_data.sql | 24 + .../gmx_v2_avalanche_c_markets_data.sql | 3 + .../gmx_v2_avalanche_c_tokens_schema.yml | 42 + .../gmx/tokens/gmx_v2_glv_markets_data.sql | 34 + .../gmx/tokens/gmx_v2_markets_data.sql | 3 + .../gmx/tokens/gmx_v2_tokens_schema.yml | 45 +- 102 files changed, 11815 insertions(+), 105 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql new file mode 100644 index 00000000000..65468f09cf8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_claimable_funding_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'claimable_funding_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ClaimableFundingAmountPerSizeUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_arbitrum.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql new file mode 100644 index 00000000000..17988609734 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCancelled' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql new file mode 100644 index 00000000000..44357cb1fbb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_created.sql @@ -0,0 +1,258 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'depositType' THEN value END) AS deposit_type, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + TRY_CAST(deposit_type AS INTEGER) AS deposit_type, + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + initial_long_token, + initial_short_token, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + deposit_type, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql new file mode 100644 index 00000000000..332c95169b7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_deposit_executed.sql @@ -0,0 +1,199 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositExecuted' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'longTokenAmount' THEN value END) AS long_token_amount, + MAX(CASE WHEN key_name = 'shortTokenAmount' THEN value END) AS short_token_amount, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(long_token_amount AS DOUBLE) AS long_token_amount, + TRY_CAST(short_token_amount AS DOUBLE) AS short_token_amount, + TRY_CAST(received_market_tokens AS DOUBLE) AS received_market_tokens, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + ED.blockchain, + ED.block_time, + DATE(ED.block_time) AS block_date, + ED.block_number, + ED.tx_hash, + ED.index, + ED.contract_address, + ED.event_name, + ED.msg_sender, + + ED.account, + ED.long_token_amount / POWER(10, MD.long_token_decimals) AS long_token_amount, + ED.short_token_amount / POWER(10, MD.short_token_decimals) AS short_token_amount, + ED.received_market_tokens / POWER(10, 18) AS received_market_tokens, + ED.swap_pricing_type, + ED."key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_deposit_created') }} AS DC + ON ED."key" = DC."key" + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON DC.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index dfc436cc271..36a4e868118 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -22,57 +22,35 @@ models: - &blockchain name: blockchain description: The blockchain network where the event occurred (Arbitrum) - data_tests: - - not_null - &block_time name: block_time description: The timestamp of the block when the event was recorded - data_tests: - - not_null - &block_date name: block_date - description: The date extracted from the block timestamp, representing the day the block was created - data_tests: - - not_null + description: The date extracted from the block timestamp, representing the day the block was created - &block_number name: block_number description: The block number where the event is included - data_tests: - - not_null - &tx_hash name: tx_hash description: The hash of the transaction where the event was logged - data_tests: - - not_null - &index name: index description: The position of the event within the transaction - data_tests: - - not_null - &contract_address name: contract_address - description: The contract address associated with the event - data_tests: - - not_null + description: The contract address associated with the event - &tx_from name: tx_from description: The originating address of the transaction, usually representing the sender - data_tests: - - not_null - &tx_to name: tx_to - description: The destination address of the transaction, representing the receiver - data_tests: - - not_null + description: The destination address of the transaction, representing the receiver - name: event_name description: The type of event recorded, always 'OrderCreated' for this model. - data_tests: - - not_null - &msg_sender name: msg_sender description: The address of the sender of the message or transaction. - data_tests: - - not_null - name: account description: The address associated with the order. - name: receiver @@ -1336,3 +1314,964 @@ models: description: The address of the keeper responsible for executing the transaction. - name: execution_fee_amount description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). + + + - name: gmx_v2_arbitrum_deposit_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'deposit_cancelled'] + description: | + Processes decoded event data for `DepositCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction details, enabling + analysis of deposit cancellations on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_arbitrum_deposit_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'deposit_created'] + description: | + Processes decoded event data for `DepositCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of deposits created on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market for which the deposit was created. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_market_tokens + description: The minimum amount of market tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: deposit_type + description: The type of deposit created. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_arbitrum_deposit_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'deposit_executed'] + description: | + Processes decoded event data for `DepositExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, execution details, and transaction specifics, enabling + analysis of deposits executed on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: long_token_amount + description: The amount of the long token in the executed deposit. + - name: short_token_amount + description: The amount of the short token in the executed deposit. + - name: received_market_tokens + description: The number of market tokens received from the executed deposit. + - name: swap_pricing_type + description: The type of swap pricing applied during the execution. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_arbitrum_glv_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_created'] + description: | + Processes decoded event data for `GLVCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the GLV token, associated tokens, and transaction specifics, enabling + analysis of GLV creation events on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVCreated` for this model. + - *msg_sender + - name: glv_token + description: The identifier of the GLV token created in the transaction. + - name: long_token + description: The long token associated with the GLV creation. + - name: short_token + description: The short token associated with the GLV creation. + - name: salt + description: A unique salt value used in the GLV creation. + - name: glv_type + description: The type of GLV created. + - name: market_token_symbol + description: The symbol of the market token involved in the GLV creation. + - name: market_token_decimals + description: The decimal precision of the market token involved in the GLV creation. + + + - name: gmx_v2_arbitrum_glv_deposit_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_deposit_cancelled'] + description: | + Processes decoded event data for `GLVDepositCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_arbitrum_glv_deposit_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_deposit_created'] + description: | + Processes decoded event data for `GLVDepositCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of created GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market associated with the deposit. + - name: glv + description: The identifier of the GLV associated with the deposit. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: ui_fee_receiver + description: The address receiving the UI fee for the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_glv_tokens + description: The minimum amount of GLV tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: market_token_amount + description: The amount of market tokens associated with the deposit. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: is_market_token_deposit + description: Indicates whether the deposit was made using market tokens. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_arbitrum_glv_deposit_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_deposit_executed'] + description: | + Processes decoded event data for `GLVDepositExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, received GLV tokens, and transaction specifics, enabling + analysis of executed GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: received_glv_tokens + description: The number of GLV tokens received from the executed deposit. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_arbitrum_glv_shift_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_shift_cancelled'] + description: | + Processes decoded event data for `GLVShiftCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the cancellation reason and transaction specifics, enabling + analysis of cancelled GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftCancelled` for this model. + - *msg_sender + - name: key + description: A unique identifier for the cancelled shift. + - name: reason_bytes + description: Encoded reason data for the shift cancellation. + - name: reason + description: The decoded textual reason for the shift cancellation. + + + - name: gmx_v2_arbitrum_glv_shift_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_shift_created'] + description: | + Processes decoded event data for `GLVShiftCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the source and destination markets, GLV details, and transaction specifics, enabling + analysis of created GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftCreated` for this model. + - *msg_sender + - name: from_market + description: The source market for the GLV shift. + - name: to_market + description: The destination market for the GLV shift. + - name: glv + description: The identifier of the GLV being shifted. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_arbitrum_glv_shift_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_shift_executed'] + description: | + Processes decoded event data for `GLVShiftExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the received market tokens and transaction specifics, enabling + analysis of executed GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftExecuted` for this model. + - *msg_sender + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_arbitrum_glv_withdrawal_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_withdrawal_cancelled'] + description: | + Processes decoded event data for `GLVWithdrawalCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalCancelled` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_arbitrum_glv_withdrawal_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_withdrawal_created'] + description: | + Processes decoded event data for `GLVWithdrawalCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalCreated` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: glv + description: The identifier of the GLV associated with the withdrawal. + - name: ui_fee_receiver + description: The address receiving the UI fee for the withdrawal. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: glv_token_amount + description: The amount of GLV tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_arbitrum_glv_withdrawal_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'glv_withdrawal_executed'] + description: | + Processes decoded event data for `GLVWithdrawalExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address and transaction specifics, enabling + analysis of executed GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_arbitrum_shift_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'shift_created'] + description: | + Processes decoded event data for `ShiftCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, market details, and transaction specifics, enabling + analysis of created shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ShiftCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the shift. + - name: receiver + description: The receiver address specified for the shift. + - name: callback_contract + description: The address of the callback contract associated with the shift. + - name: from_market + description: The source market for the shift. + - name: to_market + description: The destination market for the shift. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: execution_fee + description: The execution fee for processing the shift. + - name: callback_gas_limit + description: The gas limit for the callback associated with the shift. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_arbitrum_shift_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'shift_executed'] + description: | + Processes decoded event data for `ShiftExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, received market tokens, and transaction specifics, enabling + analysis of executed shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ShiftExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed shift. + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_arbitrum_withdrawal_cancelled + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'withdrawal_cancelled'] + description: | + Processes decoded event data for `WithdrawalCancelled` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_arbitrum_withdrawal_created + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'withdrawal_created'] + description: | + Processes decoded event data for `WithdrawalCreated` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: market_token_amount + description: The amount of market tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_arbitrum_withdrawal_executed + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'withdrawal_executed'] + description: | + Processes decoded event data for `WithdrawalExecuted` events on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as the account address, pricing type, and transaction specifics, enabling + analysis of executed withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: swap_pricing_type + description: The pricing type applied during the withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_arbitrum_claimable_funding_amount_per_size_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'claimable_funding'] + description: | + Processes decoded event data for `ClaimableFundingAmountPerSizeUpdated` events on the GMX platform across the Arbitrum blockchain. + This model extracts key details such as funding updates, collateral information, and market direction to support funding analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `ClaimableFundingAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding amount was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding amount. + - name: value + description: The funding amount value associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`true` for long, `false` for short). + + - name: gmx_v2_arbitrum_funding_fee_amount_per_size_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'funding_fee'] + description: | + Processes decoded event data for `FundingFeeAmountPerSizeUpdated` events on the GMX platform across the Arbitrum blockchain. + This model extracts key details such as funding fees, collateral details, and market direction to enable funding fee analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `FundingFeeAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding fee was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding fee amount. + - name: value + description: The funding fee amount associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`True` for long, `False` for short). diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql index c20cd8fe4f9..62b61274227 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_execution_fee_refund.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql new file mode 100644 index 00000000000..48aef2055c4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_funding_fee_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'funding_fee_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'FundingFeeAmountPerSizeUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_arbitrum.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql new file mode 100644 index 00000000000..efa07928cd6 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_created.sql @@ -0,0 +1,157 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'glvToken' THEN value END) AS glv_token, + MAX(CASE WHEN key_name = 'longToken' THEN value END) AS long_token, + MAX(CASE WHEN key_name = 'shortToken' THEN value END) AS short_token, + MAX(CASE WHEN key_name = 'salt' THEN value END) AS salt, + MAX(CASE WHEN key_name = 'glvType' THEN value END) AS glv_type + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(glv_token) AS glv_token, + from_hex(long_token) AS long_token, + from_hex(short_token) AS short_token, + from_hex(salt) AS salt, + from_hex(glv_type) AS glv_type, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql new file mode 100644 index 00000000000..347667e0461 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCancelled' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql new file mode 100644 index 00000000000..ea34140f4fc --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_created.sql @@ -0,0 +1,269 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minGlvTokens' THEN value END) AS min_glv_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + MAX(CASE WHEN key_name = 'isMarketTokenDeposit' THEN value END) AS is_market_token_deposit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, -- long_token_decimals + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, -- short_token_decimals + TRY_CAST(min_glv_tokens AS DOUBLE) min_glv_tokens, -- index_token_decimals (glv or market?) + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (glv or market?) + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + TRY_CAST(is_market_token_deposit AS BOOLEAN) AS is_market_token_deposit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + initial_long_token, + initial_short_token, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_glv_tokens / POWER(10, 18) AS min_glv_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + market_token_amount / POWER(10, 18) AS market_token_amount, + + should_unwrap_native_token, + is_market_token_deposit, + + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.market = MD.market +) + + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql new file mode 100644 index 00000000000..3302d0cbe00 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_deposit_executed.sql @@ -0,0 +1,186 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositExecuted' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedGlvTokens' THEN value END) AS received_glv_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(received_glv_tokens AS DOUBLE) received_glv_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + received_glv_tokens / POWER(10,18) AS received_glv_tokens, + "key" + + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql new file mode 100644 index 00000000000..eb06ffd6817 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_cancelled.sql @@ -0,0 +1,167 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_shift_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCancelled' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql new file mode 100644 index 00000000000..3352d8cbe46 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_created.sql @@ -0,0 +1,200 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + from_hex(glv) AS glv, + TRY_CAST(market_token_amount AS DOUBLE) AS market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) AS min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) updated_at_time, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + from_market, + to_market, + glv, + market_token_amount / POWER(10, 18) AS market_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + "key" + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql new file mode 100644 index 00000000000..106f89913c2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_shift_executed.sql @@ -0,0 +1,165 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftExecuted' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + TRY_CAST(received_market_tokens AS DOUBLE) received_market_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + received_market_tokens / POWER(10, 18) AS received_market_tokens, + "key" + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql new file mode 100644 index 00000000000..e07944f51c7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCancelled' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql new file mode 100644 index 00000000000..3aa3f886a57 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_created.sql @@ -0,0 +1,255 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'glvTokenAmount' THEN value END) AS glv_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(glv_token_amount AS DOUBLE) glv_token_amount, -- index_token_decimals (glv or market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + glv_token_amount / POWER(10, 18) AS glv_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql new file mode 100644 index 00000000000..80574bfc7c7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_glv_withdrawal_executed.sql @@ -0,0 +1,149 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalExecuted' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql index e7f2e0ee0f8..c10578e4da4 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_keeper_execution_fee.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql index 58a6f6bcb5e..77ebbce58c1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_market_created.sql @@ -49,7 +49,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql index 3d73a35efa3..e783d229c36 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_in_tokens_updated.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql index acbf9774525..2bfd18b0817 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_open_interest_updated.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql index 1e9216afe01..3f21c89db83 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_oracle_price_update.sql @@ -58,7 +58,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql index b24ca5fafe2..c7444cacce2 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_cancelled.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql index a7a9c6c1c62..366dc5709e9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_executed.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql index 289f146dcb3..132477a7d8e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql index d1cba68b7fa..947eef0660f 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_pool_amount_updated.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql index b05f68e1501..b41395df4a1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_decrease.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql index 5b142f5b386..7ef09cf95a9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_collected.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql index 8502f185856..355dc8b647d 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_fees_info.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql index 1129f3b860f..a0e6f4eaddf 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_position_increase.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql index c3a1085676b..24939abe129 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_set_uint.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql new file mode 100644 index 00000000000..18602bee501 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_created.sql @@ -0,0 +1,218 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + from_market, + to_market, + + market_token_amount / POWER(10,18) AS market_token_amount, + min_market_tokens / POWER(10,18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + "key" + + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql new file mode 100644 index 00000000000..bfe660d6dbf --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_shift_executed.sql @@ -0,0 +1,168 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftExecuted' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(received_market_tokens AS DOUBLE) / POWER(10,18) AS received_market_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql new file mode 100644 index 00000000000..e7e5a292a44 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCancelled' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql new file mode 100644 index 00000000000..c97a0b78ad3 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_created.sql @@ -0,0 +1,243 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCreated' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + + market_token_amount / POWER(10, 18) AS market_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON ED.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql new file mode 100644 index 00000000000..5456bbde74b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_withdrawal_executed.sql @@ -0,0 +1,169 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalExecuted' -%} +{%- set blockchain_name = 'arbitrum' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql new file mode 100644 index 00000000000..e2456aeb0de --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'claimable_funding_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ClaimableFundingAmountPerSizeUpdated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_avalanche_c.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql new file mode 100644 index 00000000000..41cce75f491 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCancelled' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql new file mode 100644 index 00000000000..ce9567fda4b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_created.sql @@ -0,0 +1,258 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'depositType' THEN value END) AS deposit_type, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + TRY_CAST(deposit_type AS INTEGER) AS deposit_type, + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + initial_long_token, + initial_short_token, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + deposit_type, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql new file mode 100644 index 00000000000..8271444fcf5 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_deposit_executed.sql @@ -0,0 +1,199 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'DepositExecuted' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'longTokenAmount' THEN value END) AS long_token_amount, + MAX(CASE WHEN key_name = 'shortTokenAmount' THEN value END) AS short_token_amount, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(long_token_amount AS DOUBLE) AS long_token_amount, + TRY_CAST(short_token_amount AS DOUBLE) AS short_token_amount, + TRY_CAST(received_market_tokens AS DOUBLE) AS received_market_tokens, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + ED.blockchain, + ED.block_time, + DATE(ED.block_time) AS block_date, + ED.block_number, + ED.tx_hash, + ED.index, + ED.contract_address, + ED.event_name, + ED.msg_sender, + + ED.account, + ED.long_token_amount / POWER(10, MD.long_token_decimals) AS long_token_amount, + ED.short_token_amount / POWER(10, MD.short_token_decimals) AS short_token_amount, + ED.received_market_tokens / POWER(10, 18) AS received_market_tokens, + ED.swap_pricing_type, + ED."key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_deposit_created') }} AS DC + ON ED."key" = DC."key" + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON DC.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index bd0636b0db1..f8c25f3763c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -22,57 +22,35 @@ models: - &blockchain name: blockchain description: The blockchain network where the event occurred (Avalanche) - data_tests: - - not_null - &block_time name: block_time description: The timestamp of the block when the event was recorded - data_tests: - - not_null - &block_date name: block_date - description: The date extracted from the block timestamp, representing the day the block was created - data_tests: - - not_null + description: The date extracted from the block timestamp, representing the day the block was created - &block_number name: block_number description: The block number where the event is included - data_tests: - - not_null - &tx_hash name: tx_hash description: The hash of the transaction where the event was logged - data_tests: - - not_null - &index name: index description: The position of the event within the transaction - data_tests: - - not_null - &contract_address name: contract_address description: The contract address associated with the event - data_tests: - - not_null - &tx_from name: tx_from description: The originating address of the transaction, usually representing the sender - data_tests: - - not_null - &tx_to name: tx_to - description: The destination address of the transaction, representing the receiver - data_tests: - - not_null + description: The destination address of the transaction, representing the receiver - name: event_name description: The type of event recorded, always 'OrderCreated' for this model. - data_tests: - - not_null - &msg_sender name: msg_sender description: The address of the sender of the message or transaction. - data_tests: - - not_null - name: account description: The address associated with the order. - name: receiver @@ -1337,3 +1315,963 @@ models: description: The address of the keeper responsible for executing the transaction. - name: execution_fee_amount description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). + + + - name: gmx_v2_avalanche_c_deposit_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'deposit_cancelled'] + description: | + Processes decoded event data for `DepositCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction details, enabling + analysis of deposit cancellations on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_avalanche_c_deposit_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'deposit_created'] + description: | + Processes decoded event data for `DepositCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of deposits created on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market for which the deposit was created. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_market_tokens + description: The minimum amount of market tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: deposit_type + description: The type of deposit created. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_avalanche_c_deposit_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'deposit_executed'] + description: | + Processes decoded event data for `DepositExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, execution details, and transaction specifics, enabling + analysis of deposits executed on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: long_token_amount + description: The amount of the long token in the executed deposit. + - name: short_token_amount + description: The amount of the short token in the executed deposit. + - name: received_market_tokens + description: The number of market tokens received from the executed deposit. + - name: swap_pricing_type + description: The type of swap pricing applied during the execution. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_avalanche_c_glv_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_created'] + description: | + Processes decoded event data for `GLVCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the GLV token, associated tokens, and transaction specifics, enabling + analysis of GLV creation events on the platform. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVCreated` for this model. + - *msg_sender + - name: glv_token + description: The identifier of the GLV token created in the transaction. + - name: long_token + description: The long token associated with the GLV creation. + - name: short_token + description: The short token associated with the GLV creation. + - name: salt + description: A unique salt value used in the GLV creation. + - name: glv_type + description: The type of GLV created. + - name: market_token_symbol + description: The symbol of the market token involved in the GLV creation. + - name: market_token_decimals + description: The decimal precision of the market token involved in the GLV creation. + + + - name: gmx_v2_avalanche_c_glv_deposit_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_deposit_cancelled'] + description: | + Processes decoded event data for `GLVDepositCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_avalanche_c_glv_deposit_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_deposit_created'] + description: | + Processes decoded event data for `GLVDepositCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of created GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market associated with the deposit. + - name: glv + description: The identifier of the GLV associated with the deposit. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: ui_fee_receiver + description: The address receiving the UI fee for the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_glv_tokens + description: The minimum amount of GLV tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: market_token_amount + description: The amount of market tokens associated with the deposit. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: is_market_token_deposit + description: Indicates whether the deposit was made using market tokens. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_avalanche_c_glv_deposit_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_deposit_executed'] + description: | + Processes decoded event data for `GLVDepositExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, received GLV tokens, and transaction specifics, enabling + analysis of executed GLV deposits. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: received_glv_tokens + description: The number of GLV tokens received from the executed deposit. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_avalanche_c_glv_shift_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_shift_cancelled'] + description: | + Processes decoded event data for `GLVShiftCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the cancellation reason and transaction specifics, enabling + analysis of cancelled GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftCancelled` for this model. + - *msg_sender + - name: key + description: A unique identifier for the cancelled shift. + - name: reason_bytes + description: Encoded reason data for the shift cancellation. + - name: reason + description: The decoded textual reason for the shift cancellation. + + + - name: gmx_v2_avalanche_c_glv_shift_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_shift_created'] + description: | + Processes decoded event data for `GLVShiftCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the source and destination markets, GLV details, and transaction specifics, enabling + analysis of created GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftCreated` for this model. + - *msg_sender + - name: from_market + description: The source market for the GLV shift. + - name: to_market + description: The destination market for the GLV shift. + - name: glv + description: The identifier of the GLV being shifted. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_avalanche_c_glv_shift_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_shift_executed'] + description: | + Processes decoded event data for `GLVShiftExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the received market tokens and transaction specifics, enabling + analysis of executed GLV shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftExecuted` for this model. + - *msg_sender + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_avalanche_c_glv_withdrawal_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_withdrawal_cancelled'] + description: | + Processes decoded event data for `GLVWithdrawalCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalCancelled` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_avalanche_c_glv_withdrawal_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_withdrawal_created'] + description: | + Processes decoded event data for `GLVWithdrawalCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalCreated` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: glv + description: The identifier of the GLV associated with the withdrawal. + - name: ui_fee_receiver + description: The address receiving the UI fee for the withdrawal. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: glv_token_amount + description: The amount of GLV tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_avalanche_c_glv_withdrawal_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'glv_withdrawal_executed'] + description: | + Processes decoded event data for `GLVWithdrawalExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address and transaction specifics, enabling + analysis of executed GLV withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_avalanche_c_shift_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'shift_created'] + description: | + Processes decoded event data for `ShiftCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, market details, and transaction specifics, enabling + analysis of created shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ShiftCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the shift. + - name: receiver + description: The receiver address specified for the shift. + - name: callback_contract + description: The address of the callback contract associated with the shift. + - name: from_market + description: The source market for the shift. + - name: to_market + description: The destination market for the shift. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: execution_fee + description: The execution fee for processing the shift. + - name: callback_gas_limit + description: The gas limit for the callback associated with the shift. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_avalanche_c_shift_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'shift_executed'] + description: | + Processes decoded event data for `ShiftExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, received market tokens, and transaction specifics, enabling + analysis of executed shifts. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ShiftExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed shift. + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_avalanche_c_withdrawal_cancelled + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'withdrawal_cancelled'] + description: | + Processes decoded event data for `WithdrawalCancelled` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_avalanche_c_withdrawal_created + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'withdrawal_created'] + description: | + Processes decoded event data for `WithdrawalCreated` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: market_token_amount + description: The amount of market tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_avalanche_c_withdrawal_executed + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'withdrawal_executed'] + description: | + Processes decoded event data for `WithdrawalExecuted` events on the GMX platform in the Avalanche blockchain. + This model extracts key details such as the account address, pricing type, and transaction specifics, enabling + analysis of executed withdrawals. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: swap_pricing_type + description: The pricing type applied during the withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + - name: gmx_v2_avalanche_c_claimable_funding_amount_per_size_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'claimable_funding'] + description: | + Processes decoded event data for `ClaimableFundingAmountPerSizeUpdated` events on the GMX platform across the Avalanche blockchain. + This model extracts key details such as funding updates, collateral information, and market direction to support funding analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `ClaimableFundingAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding amount was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding amount. + - name: value + description: The funding amount value associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`true` for long, `false` for short). + + - name: gmx_v2_avalanche_c_funding_fee_amount_per_size_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'funding_fee'] + description: | + Processes decoded event data for `FundingFeeAmountPerSizeUpdated` events on the GMX platform across the Avalanche blockchain. + This model extracts key details such as funding fees, collateral details, and market direction to enable funding fee analysis. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - index + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `FundingFeeAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding fee was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding fee amount. + - name: value + description: The funding fee amount associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`True` for long, `False` for short). diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql index 2fa2e95fe43..f685312857d 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_execution_fee_refund.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql new file mode 100644 index 00000000000..a2f93f4f0f8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_funding_fee_amount_per_size_updated.sql @@ -0,0 +1,195 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'funding_fee_amount_per_size_updated', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'FundingFeeAmountPerSizeUpdated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'collateralToken' THEN value END) AS collateral_token, + MAX(CASE WHEN key_name = 'delta' THEN value END) AS delta, + MAX(CASE WHEN key_name = 'value' THEN value END) AS "value", + MAX(CASE WHEN key_name = 'isLong' THEN value END) AS is_long + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(market) AS market, + from_hex(collateral_token) AS collateral_token, + TRY_CAST(delta AS DOUBLE) delta, + TRY_CAST("value" AS DOUBLE) "value", + TRY_CAST(is_long AS BOOLEAN) AS is_long + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + market, + ED.collateral_token, + delta / POWER(10, CTD.collateral_token_decimals + 15) AS delta, + "value" / POWER(10, CTD.collateral_token_decimals + 15) AS "value", + is_long + + FROM event_data AS ED + LEFT JOIN gmx_v2_avalanche_c.collateral_tokens_data AS CTD + ON ED.collateral_token = CTD.collateral_token +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql new file mode 100644 index 00000000000..1dc64b7568b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_created.sql @@ -0,0 +1,157 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'glvToken' THEN value END) AS glv_token, + MAX(CASE WHEN key_name = 'longToken' THEN value END) AS long_token, + MAX(CASE WHEN key_name = 'shortToken' THEN value END) AS short_token, + MAX(CASE WHEN key_name = 'salt' THEN value END) AS salt, + MAX(CASE WHEN key_name = 'glvType' THEN value END) AS glv_type + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(glv_token) AS glv_token, + from_hex(long_token) AS long_token, + from_hex(short_token) AS short_token, + from_hex(salt) AS salt, + from_hex(glv_type) AS glv_type, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql new file mode 100644 index 00000000000..863c2643169 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_deposit_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCancelled' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql new file mode 100644 index 00000000000..c5c9f968d07 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_created.sql @@ -0,0 +1,269 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_deposit_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'initialLongToken' THEN value END) AS initial_long_token, + MAX(CASE WHEN key_name = 'initialShortToken' THEN value END) AS initial_short_token, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'initialLongTokenAmount' THEN value END) AS initial_long_token_amount, + MAX(CASE WHEN key_name = 'initialShortTokenAmount' THEN value END) AS initial_short_token_amount, + MAX(CASE WHEN key_name = 'minGlvTokens' THEN value END) AS min_glv_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + MAX(CASE WHEN key_name = 'isMarketTokenDeposit' THEN value END) AS is_market_token_deposit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(initial_long_token) AS initial_long_token, + from_hex(initial_short_token) AS initial_short_token, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(initial_long_token_amount AS DOUBLE) initial_long_token_amount, -- long_token_decimals + TRY_CAST(initial_short_token_amount AS DOUBLE) initial_short_token_amount, -- short_token_decimals + TRY_CAST(min_glv_tokens AS DOUBLE) min_glv_tokens, -- index_token_decimals (glv or market?) + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (glv or market?) + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + TRY_CAST(is_market_token_deposit AS BOOLEAN) AS is_market_token_deposit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + initial_long_token, + initial_short_token, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + initial_long_token_amount / POWER(10, MD.long_token_decimals) AS initial_long_token_amount, + initial_short_token_amount / POWER(10, MD.short_token_decimals) AS initial_short_token_amount, + min_glv_tokens / POWER(10, 18) AS min_glv_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + market_token_amount / POWER(10, 18) AS market_token_amount, + + should_unwrap_native_token, + is_market_token_deposit, + + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.market = MD.market +) + + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql new file mode 100644 index 00000000000..f24cd674f4c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_deposit_executed.sql @@ -0,0 +1,186 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_deposit_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvDepositExecuted' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedGlvTokens' THEN value END) AS received_glv_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(received_glv_tokens AS DOUBLE) received_glv_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + received_glv_tokens / POWER(10,18) AS received_glv_tokens, + "key" + + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql new file mode 100644 index 00000000000..4a3c61e65e4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_cancelled.sql @@ -0,0 +1,167 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_shift_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCancelled' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql new file mode 100644 index 00000000000..397886221ad --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_created.sql @@ -0,0 +1,200 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + from_hex(glv) AS glv, + TRY_CAST(market_token_amount AS DOUBLE) AS market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) AS min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) updated_at_time, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + from_market, + to_market, + glv, + market_token_amount / POWER(10, 18) AS market_token_amount, + min_market_tokens / POWER(10, 18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + "key" + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql new file mode 100644 index 00000000000..f07679676cb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_shift_executed.sql @@ -0,0 +1,165 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvShiftExecuted' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + TRY_CAST(received_market_tokens AS DOUBLE) received_market_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + received_market_tokens / POWER(10, 18) AS received_market_tokens, + "key" + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql new file mode 100644 index 00000000000..9c9a58a940f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCancelled' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql new file mode 100644 index 00000000000..ab1baf9bcd1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_created.sql @@ -0,0 +1,255 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + MAX(CASE WHEN key_name = 'glv' THEN value END) AS glv, + MAX(CASE WHEN key_name = 'uiFeeReceiver' THEN value END) AS ui_fee_receiver, + MAX(CASE WHEN key_name = 'longTokenSwapPath' THEN value END) AS long_token_swap_path, + MAX(CASE WHEN key_name = 'shortTokenSwapPath' THEN value END) AS short_token_swap_path, + + MAX(CASE WHEN key_name = 'glvTokenAmount' THEN value END) AS glv_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + from_hex(glv) AS glv, + from_hex(ui_fee_receiver) AS ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + TRY_CAST(glv_token_amount AS DOUBLE) glv_token_amount, -- index_token_decimals (glv or market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + glv, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + + glv_token_amount / POWER(10, 18) AS glv_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql new file mode 100644 index 00000000000..b1d43e8e510 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_glv_withdrawal_executed.sql @@ -0,0 +1,149 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'GlvWithdrawalExecuted' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql index 3a6c16d6009..69ea1e6771f 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_keeper_execution_fee.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql index 9979092e3ef..93ac2def471 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_market_created.sql @@ -49,7 +49,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql index d601703949e..9f82c578bca 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_in_tokens_updated.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql index cd88f284349..fbb392ff855 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_open_interest_updated.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql index 14f2540c8f6..0c5d6121b68 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_oracle_price_update.sql @@ -58,7 +58,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql index e974c4d20e5..b38eb38e5cc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_cancelled.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql index d0f775d745e..5a28248d8c1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_executed.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql index 6e9b7ce230c..9651369a61e 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql index 17c7d2934da..8f2ee6167cd 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_pool_amount_updated.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql index a5edbae87fc..9870ebd74fc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_decrease.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql index ad4015404f2..d138becbf80 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_collected.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql index a4aae5dd017..092bf293fdf 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_fees_info.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql index 52d9bd0cddb..da0e3bde9b2 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_position_increase.sql @@ -53,7 +53,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql index 41e06b529d5..7d7b60cc0a9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_set_uint.sql @@ -54,7 +54,7 @@ WITH evt_data_1 AS ( , evt_data AS ( SELECT * FROM evt_data_1 - UNION + UNION ALL SELECT * FROM evt_data_2 ) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql new file mode 100644 index 00000000000..c0e8906b3c4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_created.sql @@ -0,0 +1,218 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'shift_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'fromMarket' THEN value END) AS from_market, + MAX(CASE WHEN key_name = 'toMarket' THEN value END) AS to_market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minMarketTokens' THEN value END) AS min_market_tokens, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(from_market) AS from_market, + from_hex(to_market) AS to_market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, + TRY_CAST(min_market_tokens AS DOUBLE) min_market_tokens, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + from_market, + to_market, + + market_token_amount / POWER(10,18) AS market_token_amount, + min_market_tokens / POWER(10,18) AS min_market_tokens, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + "key" + + FROM event_data AS ED +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql new file mode 100644 index 00000000000..7e5d1068301 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_shift_executed.sql @@ -0,0 +1,168 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'shift_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'ShiftExecuted' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receivedMarketTokens' THEN value END) AS received_market_tokens, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(received_market_tokens AS DOUBLE) / POWER(10,18) AS received_market_tokens, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql new file mode 100644 index 00000000000..5ec6ef12537 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_cancelled.sql @@ -0,0 +1,187 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'withdrawal_cancelled', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCancelled' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key", + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex("key") AS "key", + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql new file mode 100644 index 00000000000..f42e389f09c --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_created.sql @@ -0,0 +1,243 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'withdrawal_created', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalCreated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.boolItems' OMIT QUOTES) AS bool_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bool_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bool_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bool_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'receiver' THEN value END) AS receiver, + MAX(CASE WHEN key_name = 'callbackContract' THEN value END) AS callback_contract, + MAX(CASE WHEN key_name = 'market' THEN value END) AS market, + + MAX(CASE WHEN key_name = 'marketTokenAmount' THEN value END) AS market_token_amount, + MAX(CASE WHEN key_name = 'minLongTokenAmount' THEN value END) AS min_long_token_amount, + MAX(CASE WHEN key_name = 'minShortTokenAmount' THEN value END) AS min_short_token_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time, + MAX(CASE WHEN key_name = 'executionFee' THEN value END) AS execution_fee, + MAX(CASE WHEN key_name = 'callbackGasLimit' THEN value END) AS callback_gas_limit, + + MAX(CASE WHEN key_name = 'shouldUnwrapNativeToken' THEN value END) AS should_unwrap_native_token, + + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + from_hex(receiver) AS receiver, + from_hex(callback_contract) AS callback_contract, + from_hex(market) AS market, + + TRY_CAST(market_token_amount AS DOUBLE) market_token_amount, -- index_token_decimals (market?) + TRY_CAST(min_long_token_amount AS DOUBLE) min_long_token_amount, -- long_token_decimals + TRY_CAST(min_short_token_amount AS DOUBLE) min_short_token_amount, -- short_token_decimals + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time, + TRY_CAST(execution_fee AS DOUBLE) AS execution_fee, -- POWER(10, 18) + TRY_CAST(callback_gas_limit AS DOUBLE) AS callback_gas_limit, -- no decimals, keep as raw values + + TRY_CAST(should_unwrap_native_token AS BOOLEAN) AS should_unwrap_native_token, + + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + tx_hash, + index, + contract_address, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + ED.market, + + market_token_amount / POWER(10, 18) AS market_token_amount, + min_long_token_amount / POWER(10, MD.long_token_decimals) AS min_long_token_amount, + min_short_token_amount / POWER(10, MD.short_token_decimals) AS min_short_token_amount, + CASE + WHEN updated_at_time = 0 THEN NULL + ELSE updated_at_time + END AS updated_at_time, + execution_fee / POWER(10, 18) AS execution_fee, + callback_gas_limit, + + should_unwrap_native_token, + "key" + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON ED.market = MD.market +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql new file mode 100644 index 00000000000..b7a17202a3d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_withdrawal_executed.sql @@ -0,0 +1,169 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'withdrawal_executed', + materialized = 'incremental', + unique_key = ['tx_hash', 'index'], + incremental_strategy = 'merge' + ) +}} + +{%- set event_name = 'WithdrawalExecuted' -%} +{%- set blockchain_name = 'avalanche_c' -%} + + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + {% if is_incremental() %} + AND {{ incremental_predicate('evt_block_time') }} + {% endif %} +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION ALL + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items + FROM + evt_data +) + + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed + UNION ALL + SELECT * + FROM bytes32_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'swapPricingType' THEN value END) AS swap_pricing_type, + MAX(CASE WHEN key_name = 'key' THEN value END) AS "key" + + FROM + combined + GROUP BY tx_hash, index +) + +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(account) AS account, + TRY_CAST(swap_pricing_type AS INTEGER) AS swap_pricing_type, + from_hex("key") AS "key" + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql new file mode 100644 index 00000000000..234a369761b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_claimable_funding_amount_per_size_updated.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'claimable_funding_amount_per_size_updated', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + market, + collateral_token, + delta, + "value", + is_long +FROM {{ ref('gmx_v2_' ~ chain ~ '_claimable_funding_amount_per_size_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql new file mode 100644 index 00000000000..f82c94e76db --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_cancelled.sql @@ -0,0 +1,39 @@ +{{ config( + schema='gmx_v2', + alias = 'deposit_cancelled', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + account, + "key", + reason_bytes, + reason +FROM {{ ref('gmx_v2_' ~ chain ~ '_deposit_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql new file mode 100644 index 00000000000..4ee27fc9ff4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_created.sql @@ -0,0 +1,51 @@ +{{ config( + schema='gmx_v2', + alias = 'deposit_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + account, + receiver, + callback_contract, + market, + initial_long_token, + initial_short_token, + long_token_swap_path, + short_token_swap_path, + initial_long_token_amount, + initial_short_token_amount, + min_market_tokens, + updated_at_time, + execution_fee, + callback_gas_limit, + deposit_type, + should_unwrap_native_token, + "key" +FROM {{ ref('gmx_v2_' ~ chain ~ '_deposit_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql new file mode 100644 index 00000000000..57d159c87df --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_deposit_executed.sql @@ -0,0 +1,43 @@ +{{ config( + schema='gmx_v2', + alias = 'deposit_executed', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + long_token_amount, + short_token_amount, + received_market_tokens, + swap_pricing_type, + "key" +FROM {{ ref('gmx_v2_' ~ chain ~ '_deposit_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index 39ea55ccbab..f6783776688 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -23,57 +23,35 @@ models: - &blockchain name: blockchain description: The blockchain network where the event occurred - data_tests: - - not_null - &block_time name: block_time description: The timestamp of the block when the event was recorded - data_tests: - - not_null - &block_date name: block_date - description: The date extracted from the block timestamp, representing the day the block was created - data_tests: - - not_null + description: The date extracted from the block timestamp, representing the day the block was created - &block_number name: block_number description: The block number where the event is included - data_tests: - - not_null - &tx_hash name: tx_hash description: The hash of the transaction where the event was logged - data_tests: - - not_null - &index name: index description: The position of the event within the transaction - data_tests: - - not_null - &contract_address name: contract_address description: The contract address associated with the event - data_tests: - - not_null - &tx_from name: tx_from description: The originating address of the transaction, usually representing the sender - data_tests: - - not_null - &tx_to name: tx_to - description: The destination address of the transaction, representing the receiver - data_tests: - - not_null + description: The destination address of the transaction, representing the receiver - name: event_name description: The type of event recorded, always 'OrderCreated' for this model. - data_tests: - - not_null - &msg_sender name: msg_sender description: The address of the sender of the message or transaction. - data_tests: - - not_null - name: account description: The address associated with the order. - name: receiver @@ -1284,3 +1262,882 @@ models: description: The amount of the execution fee, denominated in the native token of the blockchain (e.g., ETH, AVAX). + - name: gmx_v2_deposit_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'deposit_cancelled'] + description: | + Processes decoded event data for `DepositCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction details, enabling + analysis of deposit cancellations on the platform. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_deposit_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'deposit_created'] + description: | + Processes decoded event data for `DepositCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of deposits created on the platform. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market for which the deposit was created. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_market_tokens + description: The minimum amount of market tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: deposit_type + description: The type of deposit created. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_deposit_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'deposit_executed'] + description: | + Processes decoded event data for `DepositExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, execution details, and transaction specifics, enabling + analysis of deposits executed on the platform. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `DepositExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: long_token_amount + description: The amount of the long token in the executed deposit. + - name: short_token_amount + description: The amount of the short token in the executed deposit. + - name: received_market_tokens + description: The number of market tokens received from the executed deposit. + - name: swap_pricing_type + description: The type of swap pricing applied during the execution. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_glv_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_created'] + description: | + Processes decoded event data for `GLVCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the GLV token, associated tokens, and transaction specifics, enabling + analysis of GLV creation events on the platform. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVCreated` for this model. + - *msg_sender + - name: glv_token + description: The identifier of the GLV token created in the transaction. + - name: long_token + description: The long token associated with the GLV creation. + - name: short_token + description: The short token associated with the GLV creation. + - name: salt + description: A unique salt value used in the GLV creation. + - name: glv_type + description: The type of GLV created. + - name: market_token_symbol + description: The symbol of the market token involved in the GLV creation. + - name: market_token_decimals + description: The decimal precision of the market token involved in the GLV creation. + + + - name: gmx_v2_glv_deposit_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_deposit_cancelled'] + description: | + Processes decoded event data for `GLVDepositCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV deposits. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled deposit. + - name: key + description: A unique identifier for the cancelled deposit. + - name: reason_bytes + description: Encoded reason data for the deposit cancellation. + - name: reason + description: The decoded textual reason for the deposit cancellation. + + + - name: gmx_v2_glv_deposit_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_deposit_created'] + description: | + Processes decoded event data for `GLVDepositCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, deposit details, and transaction specifics, enabling + analysis of created GLV deposits. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the deposit. + - name: receiver + description: The receiver address specified for the deposit. + - name: callback_contract + description: The address of the callback contract associated with the deposit. + - name: market + description: The market associated with the deposit. + - name: glv + description: The identifier of the GLV associated with the deposit. + - name: initial_long_token + description: The token used for the long position in the deposit. + - name: initial_short_token + description: The token used for the short position in the deposit. + - name: ui_fee_receiver + description: The address receiving the UI fee for the deposit. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: initial_long_token_amount + description: The initial amount of the long token in the deposit. + - name: initial_short_token_amount + description: The initial amount of the short token in the deposit. + - name: min_glv_tokens + description: The minimum amount of GLV tokens expected from the deposit. + - name: updated_at_time + description: The timestamp when the deposit was last updated. + - name: execution_fee + description: The execution fee for processing the deposit. + - name: callback_gas_limit + description: The gas limit for the callback associated with the deposit. + - name: market_token_amount + description: The amount of market tokens associated with the deposit. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: is_market_token_deposit + description: Indicates whether the deposit was made using market tokens. + - name: key + description: A unique identifier for the deposit. + + + - name: gmx_v2_glv_deposit_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_deposit_executed'] + description: | + Processes decoded event data for `GLVDepositExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, received GLV tokens, and transaction specifics, enabling + analysis of executed GLV deposits. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVDepositExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed deposit. + - name: received_glv_tokens + description: The number of GLV tokens received from the executed deposit. + - name: key + description: A unique identifier for the executed deposit. + + + - name: gmx_v2_glv_shift_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_shift_cancelled'] + description: | + Processes decoded event data for `GLVShiftCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the cancellation reason and transaction specifics, enabling + analysis of cancelled GLV shifts. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftCancelled` for this model. + - *msg_sender + - name: key + description: A unique identifier for the cancelled shift. + - name: reason_bytes + description: Encoded reason data for the shift cancellation. + - name: reason + description: The decoded textual reason for the shift cancellation. + + + - name: gmx_v2_glv_shift_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_shift_created'] + description: | + Processes decoded event data for `GLVShiftCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the source and destination markets, GLV details, and transaction specifics, enabling + analysis of created GLV shifts. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftCreated` for this model. + - *msg_sender + - name: from_market + description: The source market for the GLV shift. + - name: to_market + description: The destination market for the GLV shift. + - name: glv + description: The identifier of the GLV being shifted. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_glv_shift_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_shift_executed'] + description: | + Processes decoded event data for `GLVShiftExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the received market tokens and transaction specifics, enabling + analysis of executed GLV shifts. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVShiftExecuted` for this model. + - *msg_sender + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_glv_withdrawal_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_withdrawal_cancelled'] + description: | + Processes decoded event data for `GLVWithdrawalCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled GLV withdrawals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalCancelled` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_glv_withdrawal_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_withdrawal_created'] + description: | + Processes decoded event data for `GLVWithdrawalCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created GLV withdrawals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalCreated` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: glv + description: The identifier of the GLV associated with the withdrawal. + - name: ui_fee_receiver + description: The address receiving the UI fee for the withdrawal. + - name: long_token_swap_path + description: The swap path for the long token. + - name: short_token_swap_path + description: The swap path for the short token. + - name: glv_token_amount + description: The amount of GLV tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_glv_withdrawal_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'glv_withdrawal_executed'] + description: | + Processes decoded event data for `GLVWithdrawalExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address and transaction specifics, enabling + analysis of executed GLV withdrawals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `GLVWithdrawalExecuted` for this model. + data_tests: + - not_null + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_shift_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'shift_created'] + description: | + Processes decoded event data for `ShiftCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, market details, and transaction specifics, enabling + analysis of created shifts. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ShiftCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the shift. + - name: receiver + description: The receiver address specified for the shift. + - name: callback_contract + description: The address of the callback contract associated with the shift. + - name: from_market + description: The source market for the shift. + - name: to_market + description: The destination market for the shift. + - name: market_token_amount + description: The amount of market tokens involved in the shift. + - name: min_market_tokens + description: The minimum market tokens expected from the shift. + - name: updated_at_time + description: The timestamp when the shift was last updated. + - name: execution_fee + description: The execution fee for processing the shift. + - name: callback_gas_limit + description: The gas limit for the callback associated with the shift. + - name: key + description: A unique identifier for the created shift. + + + - name: gmx_v2_shift_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'shift_executed'] + description: | + Processes decoded event data for `ShiftExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, received market tokens, and transaction specifics, enabling + analysis of executed shifts. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `ShiftExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed shift. + - name: received_market_tokens + description: The number of market tokens received from the executed shift. + - name: key + description: A unique identifier for the executed shift. + + + - name: gmx_v2_withdrawal_cancelled + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'withdrawal_cancelled'] + description: | + Processes decoded event data for `WithdrawalCancelled` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, cancellation reason, and transaction specifics, enabling + analysis of cancelled withdrawals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalCancelled` for this model. + - *msg_sender + - name: account + description: The account address associated with the cancelled withdrawal. + - name: key + description: A unique identifier for the cancelled withdrawal. + - name: reason_bytes + description: Encoded reason data for the withdrawal cancellation. + - name: reason + description: The decoded textual reason for the withdrawal cancellation. + + + - name: gmx_v2_withdrawal_created + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'withdrawal_created'] + description: | + Processes decoded event data for `WithdrawalCreated` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, withdrawal details, and transaction specifics, enabling + analysis of created withdrawals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalCreated` for this model. + - *msg_sender + - name: account + description: The account address associated with the withdrawal. + - name: receiver + description: The receiver address specified for the withdrawal. + - name: callback_contract + description: The address of the callback contract associated with the withdrawal. + - name: market + description: The market associated with the withdrawal. + - name: market_token_amount + description: The amount of market tokens involved in the withdrawal. + - name: min_long_token_amount + description: The minimum long token amount expected from the withdrawal. + - name: min_short_token_amount + description: The minimum short token amount expected from the withdrawal. + - name: updated_at_time + description: The timestamp when the withdrawal was last updated. + - name: execution_fee + description: The execution fee for processing the withdrawal. + - name: callback_gas_limit + description: The gas limit for the callback associated with the withdrawal. + - name: should_unwrap_native_token + description: Indicates whether the native token should be unwrapped. + - name: key + description: A unique identifier for the created withdrawal. + + + - name: gmx_v2_withdrawal_executed + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'withdrawal_executed'] + description: | + Processes decoded event data for `WithdrawalExecuted` events on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as the account address, pricing type, and transaction specifics, enabling + analysis of executed withdrawals. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address that initiated the transaction. + - name: tx_to + description: The destination address of the transaction. + - name: event_name + description: The type of event recorded, always `WithdrawalExecuted` for this model. + - *msg_sender + - name: account + description: The account address associated with the executed withdrawal. + - name: swap_pricing_type + description: The pricing type applied during the withdrawal. + - name: key + description: A unique identifier for the executed withdrawal. + + + - name: gmx_v2_claimable_funding_amount_per_size_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'claimable_funding'] + description: | + Processes decoded event data for `ClaimableFundingAmountPerSizeUpdated` events on the GMX platform across the Arbitrum and Avalanche blockchains. + This model extracts key details such as funding updates, collateral information, and market direction to support funding analysis. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `ClaimableFundingAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding amount was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding amount. + - name: value + description: The funding amount value associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`true` for long, `false` for short). + + - name: gmx_v2_funding_fee_amount_per_size_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'funding_fee'] + description: | + Processes decoded event data for `FundingFeeAmountPerSizeUpdated` events on the GMX platform across the Arbitrum and Avalanche blockchains. + This model extracts key details such as funding fees, collateral details, and market direction to enable funding fee analysis. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - name: tx_from + description: The address initiating the transaction. + - name: tx_to + description: The recipient address of the transaction. + - name: event_name + description: The name of the event emitted, always `FundingFeeAmountPerSizeUpdated`. + - *msg_sender + - name: market + description: The specific GMX market where the funding fee was updated. + - name: collateral_token + description: The token used as collateral in the funding event. + - name: delta + description: The change in the funding fee amount. + - name: value + description: The funding fee amount associated with the update. + - name: is_long + description: A boolean indicating if the position is a long position (`True` for long, `False` for short). diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql new file mode 100644 index 00000000000..77db6dab786 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_funding_fee_amount_per_size_updated.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'funding_fee_amount_per_size_updated', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + market, + collateral_token, + delta, + "value", + is_long +FROM {{ ref('gmx_v2_' ~ chain ~ '_funding_fee_amount_per_size_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql new file mode 100644 index 00000000000..3ff0d276649 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_created.sql @@ -0,0 +1,44 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + glv_token, + long_token, + short_token, + salt, + glv_type, + market_token_symbol, + market_token_decimals + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql new file mode 100644 index 00000000000..a94e78ae3f1 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_cancelled.sql @@ -0,0 +1,42 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_deposit_cancelled', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_deposit_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql new file mode 100644 index 00000000000..550dbdac8ff --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_created.sql @@ -0,0 +1,56 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_deposit_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + market, + glv, + initial_long_token, + initial_short_token, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + initial_long_token_amount, + initial_short_token_amount, + min_glv_tokens, + updated_at_time, + execution_fee, + callback_gas_limit, + market_token_amount, + should_unwrap_native_token, + is_market_token_deposit, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_deposit_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql new file mode 100644 index 00000000000..2a8ffc7a0a7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_deposit_executed.sql @@ -0,0 +1,42 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_deposit_executed', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + received_glv_tokens, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_deposit_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql new file mode 100644 index 00000000000..93b1164153e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_cancelled.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_shift_cancelled', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_shift_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql new file mode 100644 index 00000000000..eb1a077a283 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_created.sql @@ -0,0 +1,44 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_shift_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + from_market, + to_market, + glv, + market_token_amount, + min_market_tokens, + updated_at_time, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_shift_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql new file mode 100644 index 00000000000..8b5098727a0 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_shift_executed.sql @@ -0,0 +1,39 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_shift_executed', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + received_market_tokens, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_shift_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql new file mode 100644 index 00000000000..e13c2bfe157 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_cancelled.sql @@ -0,0 +1,42 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_withdrawal_cancelled', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_withdrawal_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql new file mode 100644 index 00000000000..85faee03b17 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_created.sql @@ -0,0 +1,52 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_withdrawal_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + market, + glv, + ui_fee_receiver, + long_token_swap_path, + short_token_swap_path, + glv_token_amount, + min_long_token_amount, + min_short_token_amount, + updated_at_time, + execution_fee, + callback_gas_limit, + should_unwrap_native_token, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_withdrawal_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql new file mode 100644 index 00000000000..5fd5d1de1e2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_glv_withdrawal_executed.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_withdrawal_executed', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_withdrawal_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql new file mode 100644 index 00000000000..e79bb2d2a80 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_created.sql @@ -0,0 +1,49 @@ +{{ config( + schema='gmx_v2', + alias = 'shift_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + from_market, + to_market, + market_token_amount, + min_market_tokens, + updated_at_time, + execution_fee, + callback_gas_limit, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_shift_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql new file mode 100644 index 00000000000..4407f016586 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_shift_executed.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'shift_executed', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + received_market_tokens, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_shift_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql new file mode 100644 index 00000000000..a1199d59838 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_cancelled.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'withdrawal_cancelled', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + "key", + reason_bytes, + reason + +FROM {{ ref('gmx_v2_' ~ chain ~ '_withdrawal_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql new file mode 100644 index 00000000000..527870ac98b --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_created.sql @@ -0,0 +1,49 @@ +{{ config( + schema='gmx_v2', + alias = 'withdrawal_created', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + receiver, + callback_contract, + market, + market_token_amount, + min_long_token_amount, + min_short_token_amount, + updated_at_time, + execution_fee, + callback_gas_limit, + should_unwrap_native_token, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_withdrawal_created') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql new file mode 100644 index 00000000000..be12acddb55 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_withdrawal_executed.sql @@ -0,0 +1,40 @@ +{{ config( + schema='gmx_v2', + alias = 'withdrawal_executed', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + + account, + swap_pricing_type, + "key" + +FROM {{ ref('gmx_v2_' ~ chain ~ '_withdrawal_executed') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql new file mode 100644 index 00000000000..16d2d77e07e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_glv_markets_data.sql @@ -0,0 +1,24 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'glv_markets_data', + materialized = 'view' + ) +}} + +SELECT + GCE.glv_token AS glv, + CONCAT(ERC20_LT.symbol, '-', ERC20_ST.symbol) AS glv_market_name, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals, + GCE.long_token, + ERC20_LT.symbol AS long_token_symbol, + ERC20_LT.decimals AS long_token_decimals, + GCE.short_token, + ERC20_ST.symbol AS short_token_symbol, + ERC20_ST.decimals AS short_token_decimals +FROM {{ ref('gmx_v2_arbitrum_glv_created') }} AS GCE +LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20_LT + ON ERC20_LT.contract_address = GCE.long_token +LEFT JOIN {{ ref('gmx_v2_arbitrum_erc20') }} AS ERC20_ST + ON ERC20_ST.contract_address = GCE.short_token \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql index 5c4682b2fe8..9ef54976e01 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql @@ -15,10 +15,13 @@ SELECT END AS market_name, 'GM' AS market_token_symbol, 18 AS market_token_decimals, + MCE.index_token, ERC20_IT.symbol AS index_token_symbol, ERC20_IT.decimals AS index_token_decimals, + MCE.long_token, ERC20_LT.symbol AS long_token_symbol, ERC20_LT.decimals AS long_token_decimals, + MCE.short_token, ERC20_ST.symbol AS short_token_symbol, ERC20_ST.decimals AS short_token_decimals FROM {{ ref('gmx_v2_arbitrum_market_created') }} AS MCE diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml index 5bea8c3ee7f..317ba7b82c7 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_tokens_schema.yml @@ -110,10 +110,14 @@ models: description: The number of decimal places for the market token. data_tests: - not_null + - name: index_token + description: The contract address of the index token. - name: index_token_symbol description: The symbol representing the index token in the market. - name: index_token_decimals description: The number of decimal places for the index token used in the market. + - name: long_token + description: The contract address of the long token. - name: long_token_symbol description: The symbol representing the long token in the market. data_tests: @@ -122,6 +126,8 @@ models: description: The number of decimal places for the long token used in the market. data_tests: - not_null + - name: short_token + description: The contract address of the short token. - name: short_token_symbol description: The symbol representing the short token in the market. data_tests: @@ -129,4 +135,40 @@ models: - name: short_token_decimals description: The number of decimal places for the short token used in the market. data_tests: - - not_null \ No newline at end of file + - not_null + + + - name: gmx_v2_arbitrum_glv_markets_data + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'markets', 'glv_markets_data'] + description: | + Processes decoded market data for GLV markets on the GMX platform in the Arbitrum blockchain. + This model extracts key details such as market names, token symbols, and decimals, enabling + comprehensive analysis of GLV markets. + + columns: + - name: glv + description: The identifier of the GLV market. + - name: glv_market_name + description: The name of the GLV market. + - name: market_token_symbol + description: The symbol of the market token. + - name: market_token_decimals + description: The decimal precision of the market token. + - name: long_token + description: The contract address of the long token. + - name: long_token_symbol + description: The symbol of the long token in the market. + - name: long_token_decimals + description: The decimal precision of the long token. + - name: short_token + description: The contract address of the short token. + - name: short_token_symbol + description: The symbol of the short token in the market. + - name: short_token_decimals + description: The decimal precision of the short token. diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql new file mode 100644 index 00000000000..126a8adc6fb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_glv_markets_data.sql @@ -0,0 +1,24 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'glv_markets_data', + materialized = 'view' + ) +}} + +SELECT + GCE.glv_token AS glv, + CONCAT(ERC20_LT.symbol, '-', ERC20_ST.symbol) AS glv_market_name, + 'GM' AS market_token_symbol, + 18 AS market_token_decimals, + GCE.long_token, + ERC20_LT.symbol AS long_token_symbol, + ERC20_LT.decimals AS long_token_decimals, + GCE.short_token, + ERC20_ST.symbol AS short_token_symbol, + ERC20_ST.decimals AS short_token_decimals +FROM {{ ref('gmx_v2_avalanche_c_glv_created') }} AS GCE +LEFT JOIN {{ ref('gmx_v2_avalanche_c_erc20') }} AS ERC20_LT + ON ERC20_LT.contract_address = GCE.long_token +LEFT JOIN {{ ref('gmx_v2_avalanche_c_erc20') }} AS ERC20_ST + ON ERC20_ST.contract_address = GCE.short_token \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql index c8fda944fb9..61d4a394158 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql @@ -15,10 +15,13 @@ SELECT END AS market_name, 'GM' AS market_token_symbol, 18 AS market_token_decimals, + MCE.index_token, ERC20_IT.symbol AS index_token_symbol, ERC20_IT.decimals AS index_token_decimals, + MCE.long_token, ERC20_LT.symbol AS long_token_symbol, ERC20_LT.decimals AS long_token_decimals, + MCE.short_token, ERC20_ST.symbol AS short_token_symbol, ERC20_ST.decimals AS short_token_decimals FROM {{ ref('gmx_v2_avalanche_c_market_created') }} AS MCE diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml index 572164b7ae2..279bb25881c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_tokens_schema.yml @@ -109,10 +109,14 @@ models: description: The number of decimal places for the market token. data_tests: - not_null + - name: index_token + description: The contract address of the index token. - name: index_token_symbol description: The symbol representing the index token in the market. - name: index_token_decimals description: The number of decimal places for the index token used in the market. + - name: long_token + description: The contract address of the long token. - name: long_token_symbol description: The symbol representing the long token in the market. data_tests: @@ -121,6 +125,8 @@ models: description: The number of decimal places for the long token used in the market. data_tests: - not_null + - name: short_token + description: The contract address of the short token. - name: short_token_symbol description: The symbol representing the short token in the market. data_tests: @@ -129,3 +135,39 @@ models: description: The number of decimal places for the short token used in the market. data_tests: - not_null + + + - name: gmx_v2_avalanche_c_glv_markets_data + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'markets', 'glv_markets_data'] + description: | + Processes decoded market data for GLV markets on the GMX platform in the Avalanche blockchain. + This model extracts key details such as market names, token symbols, and decimals, enabling + comprehensive analysis of GLV markets. + + columns: + - name: glv + description: The identifier of the GLV market. + - name: glv_market_name + description: The name of the GLV market. + - name: market_token_symbol + description: The symbol of the market token. + - name: market_token_decimals + description: The decimal precision of the market token. + - name: long_token + description: The contract address of the long token. + - name: long_token_symbol + description: The symbol of the long token in the market. + - name: long_token_decimals + description: The decimal precision of the long token. + - name: short_token + description: The contract address of the short token. + - name: short_token_symbol + description: The symbol of the short token in the market. + - name: short_token_decimals + description: The decimal precision of the short token. diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql new file mode 100644 index 00000000000..b0e0b15ba91 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_glv_markets_data.sql @@ -0,0 +1,34 @@ +{{ config( + schema='gmx_v2', + alias = 'glv_markets_data', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + '{{ chain }}' AS "blockchain", + glv, + glv_market_name, + market_token_symbol, + market_token_decimals, + long_token, + long_token_symbol, + long_token_decimals, + short_token, + short_token_symbol, + short_token_decimals +FROM {{ ref('gmx_v2_' ~ chain ~ '_glv_markets_data') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} + diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql index 0c0951fee6f..60a22b01370 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_markets_data.sql @@ -20,10 +20,13 @@ SELECT market_name, market_token_symbol, market_token_decimals, + index_token, index_token_symbol, index_token_decimals, + long_token, long_token_symbol, long_token_decimals, + short_token, short_token_symbol, short_token_decimals FROM {{ ref('gmx_v2_' ~ chain ~ '_markets_data') }} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml index e1c9b389c18..601a5f113d1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/gmx_v2_tokens_schema.yml @@ -110,10 +110,14 @@ models: description: The number of decimal places for the market token. data_tests: - not_null + - name: index_token + description: The contract address of the index token. - name: index_token_symbol description: The symbol representing the index token in the market. - name: index_token_decimals description: The number of decimal places for the index token used in the market. + - name: long_token + description: The contract address of the long token. - name: long_token_symbol description: The symbol representing the long token in the market. data_tests: @@ -122,6 +126,8 @@ models: description: The number of decimal places for the long token used in the market. data_tests: - not_null + - name: short_token + description: The contract address of the short token. - name: short_token_symbol description: The symbol representing the short token in the market. data_tests: @@ -129,4 +135,41 @@ models: - name: short_token_decimals description: The number of decimal places for the short token used in the market. data_tests: - - not_null \ No newline at end of file + - not_null + + + - name: gmx_v2_glv_markets_data + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'markets', 'glv_markets_data'] + description: | + Processes decoded market data for GLV markets on the GMX platform in the Arbitrum and Avalanche blockchains. + This model extracts key details such as market names, token symbols, and decimals, enabling + comprehensive analysis of GLV markets. + + columns: + - *blockchain + - name: glv + description: The identifier of the GLV market. + - name: glv_market_name + description: The name of the GLV market. + - name: market_token_symbol + description: The symbol of the market token. + - name: market_token_decimals + description: The decimal precision of the market token. + - name: long_token + description: The contract address of the long token. + - name: long_token_symbol + description: The symbol of the long token in the market. + - name: long_token_decimals + description: The decimal precision of the long token. + - name: short_token + description: The contract address of the short token. + - name: short_token_symbol + description: The symbol of the short token in the market. + - name: short_token_decimals + description: The decimal precision of the short token. From f4825b1903d846867f89f0b63e8e7bf2626409ed Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:42:23 +0000 Subject: [PATCH 17/17] add balancer v3 pools to labels_addresses (#7309) * add balancer v3 pools to labels_addresses * also add balancer_cowswap_amm_pools --------- Co-authored-by: Huang Geyang --- .../daily_spellbook/models/_sector/labels/labels_addresses.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbt_subprojects/daily_spellbook/models/_sector/labels/labels_addresses.sql b/dbt_subprojects/daily_spellbook/models/_sector/labels/labels_addresses.sql index 53e6085ec6f..3d3047c5079 100644 --- a/dbt_subprojects/daily_spellbook/models/_sector/labels/labels_addresses.sql +++ b/dbt_subprojects/daily_spellbook/models/_sector/labels/labels_addresses.sql @@ -14,6 +14,8 @@ ref('labels_aztec_v2_contracts_ethereum') , source('labels', 'labels_balancer_v1_pools') , source('labels', 'balancer_v2_pools') + , source('labels', 'balancer_v3_pools') + , source('labels', 'balancer_cowswap_amm_pools') , ref('labels_balancer_v2_gauges') , ref('labels_cex') , ref('labels_contracts')