diff --git a/data/silver_bridge__allbridge_chain_id_seed.csv b/data/silver_bridge__allbridge_chain_id_seed.csv deleted file mode 100644 index cbcd2f3..0000000 --- a/data/silver_bridge__allbridge_chain_id_seed.csv +++ /dev/null @@ -1,12 +0,0 @@ -chain,chain_id -ethereum,1 -bsc,2 -tron,3 -solana,4 -polygon,5 -arbitrum,6 -stellar,7 -avalanche,8 -base,9 -optimism,10 -celo,11 \ No newline at end of file diff --git a/data/silver_bridge__ccip_chain_seed.csv b/data/silver_bridge__ccip_chain_seed.csv deleted file mode 100644 index a3c6554..0000000 --- a/data/silver_bridge__ccip_chain_seed.csv +++ /dev/null @@ -1,75 +0,0 @@ -chain_name,chain_selector -apechain,14894068710063348487 -arbitrum,4949039107694359620 -l3x,3162193654116181371 -treasure,1010349088906777999 -areon,1939936305787790600 -astar-zkevm,1540201334317828111 -avalanche,6433500567565415381 -dexalot,5463201557265485081 -base,15971525489660198786 -berachain,1294465214383781161 -bsc,11344663589394136015 -opbnb,465944652040885897 -bitcichain,4874388048629246000 -bitlayer,7937294810946806131 -bittorrent,3776006016387883143 -blast,4411394078118774322 -bob,3849287863852499584 -botanix,4560701533377838164 -bsquared,5406759801798337480 -celo,1346049177634351622 -coinex_smart_chain,1761333065194157300 -core,1224752112135636129 -corn,9043146809313071210 -cronos,1456215246176062136 -cronos-zkevm,8788096068760390840 -ethereum,5009297550715157269 -fantom,3768048213127883732 -filecoin,4561443241176882990 -fraxtal,1462016016387883143 -gnosis,465200170687744372 -hashkey,7613811247471741961 -hedera,3229138320728879060 -immutable-zkevm,1237925231416731909 -ink,3461204551265785888 -kava,7550000543357438061 -kroma,3719320017875267166 -moonriver,1355020143337428062 -lens,5608378062013572713 -linea,4627098889531055414 -mantle,1556008542357238666 -merlin,241851231317828981 -metis,8805746078405598895 -mind,11690709103138290329 -mode,7264351850409363825 -morph,18164309074156128038 -near,2039744413822257700 -neonlink,8239338020728974000 -optimism,3734403246176062136 -plume,3208172210661564830 -astar-polkadot,6422105447186081193 -centrifuge,8175830712062617656 -darwinia,8866418665544333000 -moonbeam,1252863800116739621 -polygon,4051577828743386545 -polygon-zkevm,4348158687435793198 -private-testnet-mica,4489326297382772450 -ronin,6916147374840168594 -rootstock,11964252391146578476 -scroll,13204309965629103672 -sei,9027416829622342829 -shibarium,3993510008929295315 -soneium,12505351618335765396 -sonic,1673871237479749969 -taiko,16468599424800719238 -telos-evm,1477345371608778000 -treasure,5214452172935136222 -unichain,1923510103922296319 -velas,374210358663784372 -wemix,5142893604156789321 -worldchain,2049429975587534727 -xlayer,3016212468291539606 -zircuit,17198166215261833993 -zklink_nova,4350319965322101699 -zksync,1562403441176082196 \ No newline at end of file diff --git a/data/silver_bridge__meson_chain_id_seed.csv b/data/silver_bridge__meson_chain_id_seed.csv deleted file mode 100644 index f27fa1c..0000000 --- a/data/silver_bridge__meson_chain_id_seed.csv +++ /dev/null @@ -1,41 +0,0 @@ -chain,short_coin_type -Aptos,0x027d -Arbitrum,0x2329 -Aurora,0x0a0a -Avalanche,0x2328 -Base,0x2105 -Bitcoin,0x0000 -BNB Chain,0x02ca -Celo,0xce10 -Coinweb,0x08ae -Conflux,0x01f7 -Crypto Chain,0x018a -EOS,0x00c2 -Ethereum,0x003c -Evmos,0x11bc -Fantom,0x03ef -Flow,0x021b -Gnosis,0x02bc -Harmony,0x03ff -Linea,0xe708 -Manta,0x0263 -Mantle,0x1388 -Metis,0x0440 -Moonbeam,0x0504 -Moonriver,0x0505 -Nautilus,0x56ce -Near,0x018d -opBNB,0x00cc -Optimism,0x0266 -Polygon POS,0x03c6 -Polygon zkEVM,0x044d -Scroll,0x2750 -SKALE Europa,0x9296 -SKALE Nebula,0xb4b1 -Solana,0x01f5 -Sui,0x0310 -Terra,0x014a -Thorchain,0x03a3 -Tron,0x00c3 -zkSync Era,0x0324 -zkFair,0xa70e \ No newline at end of file diff --git a/data/silver_bridge__standard_dst_chain_seed.csv b/data/silver_bridge__standard_dst_chain_seed.csv deleted file mode 100644 index c5d8777..0000000 --- a/data/silver_bridge__standard_dst_chain_seed.csv +++ /dev/null @@ -1,98 +0,0 @@ -destination_chain,standard_destination_chain -acala,acala -algorand,algorand -aptos,aptos -arbitrum,arbitrum -arbitrum nova,arbitrum nova -arbitrum one,arbitrum -archway,archway -astar,astar -aurora,aurora -aurora mainnet,aurora -avalanche,avalanche -avalanche c-chain,avalanche -base,base -bnb,bsc -bnb chain,bsc -bnb smart chain mainnet,bsc -boba bnb mainnet,boba -boba network,boba -bsc,bsc -canto,canto -carbon,carbon -celo,celo -celo mainnet,celo -coinweb,coinweb -conflux,conflux -conflux espace,conflux -crab network,crab -crescent,crescent -cronos mainnet,cronos -crypto chain,crypto -dfk chain,dfk -dogechain mainnet,dogechain -eos,eos -ethereum,ethereum -ethereum mainnet,ethereum -evmos,evmos -fantom,fantom -fantom opera,fantom -filecoin,filecoin -fuse,fuse -gnosis,gnosis -harmony mainnet shard 0,harmony -huobi eco chain mainnet,huobi eco -injective,injective -juno,juno -karura,karura -kava,kava -klaytn,klaytn -klaytn mainnet cypress,klaytn -kujira,kujira -linea,linea -manta,manta -mantle,mantle -metis,metis -metis andromeda mainnet,metis -moonbeam,moonbeam -moonriver,moonriver -nautilus,nautilus -near,near -neutron,neutron -oasis,oasis -okxchain mainnet,okxchain -ontology mainnet,ontology -op mainnet,optimism -opbnb,opbnb -optimism,optimism -osmosis,osmosis -polygon,polygon -polygon mainnet,polygon -polygon pos,polygon -polygon zkevm,polygon zkevm -ronin,ronin -scroll,scroll -secret-snip,secret -sei,sei -skale europa,skale europa -skale nebula,skale nebula -solana,solana -stargaze,stargaze -starknet,starknet -sui,sui -telos evm mainnet,telos -terra,terra -terra-2,terra2 -terra2,terra2 -tezos,tezos -tron,tron -umee,umee -waves,waves -xpla,xpla -xrpl,xrpl -zkfair,zkfair -zksync era,zksync era -zksync era mainnet,zksync era -zksync lite,zksync lite -zora,zora -zzz,zzz diff --git a/data/silver_bridge__stargate_chain_id_seed.csv b/data/silver_bridge__stargate_chain_id_seed.csv deleted file mode 100644 index 45d58e3..0000000 --- a/data/silver_bridge__stargate_chain_id_seed.csv +++ /dev/null @@ -1,13 +0,0 @@ -chain_name,chain_id -Arbitrum,110 -Avalanche,106 -Base,184 -BNB,102 -Ethereum,101 -Fantom,112 -Kava,177 -Linea,183 -Mantle,181 -Metis,151 -Optimism,111 -Polygon,109 \ No newline at end of file diff --git a/data/silver_bridge__wormhole_chain_id_seed.csv b/data/silver_bridge__wormhole_chain_id_seed.csv deleted file mode 100644 index 122f815..0000000 --- a/data/silver_bridge__wormhole_chain_id_seed.csv +++ /dev/null @@ -1,35 +0,0 @@ -chain_name,wormhole_chain_id -acala,12 -algorand,8 -aptos,22 -arbitrum,23 -aurora,9 -avalanche,6 -base,30 -bsc,4 -celo,14 -cosmoshub,4000 -ethereum,2 -evmos,4001 -fantom,10 -gnosis,25 -injective,19 -karura,11 -klaytn,13 -kujira,4002 -moonbeam,16 -near,15 -neon,17 -oasis,7 -optimism,24 -osmosis,20 -polygon,5 -pythnet,26 -rootstock,33 -sei,32 -sepolia,10002 -solana,1 -sui,21 -terra,3 -terra2,18 -xpla,28 \ No newline at end of file diff --git a/dbt_project.yml b/dbt_project.yml index e9939ab..b25577a 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -108,6 +108,8 @@ models: +enabled: false bridge: +enabled: true + dex: + +enabled: true stats: +enabled: true scores_package: diff --git a/models/gold/defi/defi__dim_dex_liquidity_pools.sql b/models/gold/defi/defi__dim_dex_liquidity_pools.sql deleted file mode 100644 index fc8641a..0000000 --- a/models/gold/defi/defi__dim_dex_liquidity_pools.sql +++ /dev/null @@ -1,42 +0,0 @@ -{{ config( - materialized = 'view', - persist_docs ={ "relation": true, - "columns": true }, - meta={ - 'database_tags':{ - 'table': { - 'PROTOCOL': 'BALANCER, CAMELOT, CURVE, DODO, FRAXSWAP, KYBERSWAP, SUSHISWAP, TRADER JOE, UNISWAP, ZYBERSWAP', - 'PURPOSE': 'DEX, LIQUIDITY, POOLS, LP, SWAPS', - } - } - }, - tags = ['gold','defi','dex','curated'] -) }} - -SELECT - block_number AS creation_block, - block_timestamp AS creation_time, - tx_hash AS creation_tx, - platform, - contract_address AS factory_address, - pool_address, - pool_name, - tokens, - symbols, - decimals, - COALESCE ( - complete_dex_liquidity_pools_id, - {{ dbt_utils.generate_surrogate_key( - ['pool_address'] - ) }} - ) AS dim_dex_liquidity_pools_id, - COALESCE( - inserted_timestamp, - '2000-01-01' - ) AS inserted_timestamp, - COALESCE( - modified_timestamp, - '2000-01-01' - ) AS modified_timestamp -FROM - {{ ref('silver_dex__complete_dex_liquidity_pools') }} \ No newline at end of file diff --git a/models/gold/defi/defi__ez_bridge_activity.sql b/models/gold/defi/defi__ez_bridge_activity.sql deleted file mode 100644 index e48d1e3..0000000 --- a/models/gold/defi/defi__ez_bridge_activity.sql +++ /dev/null @@ -1,63 +0,0 @@ -{{ config( - materialized = 'view', - persist_docs ={ "relation": true, - "columns": true }, - meta ={ - 'database_tags':{ - 'table':{ - 'PROTOCOL': 'ACROSS, AXELAR, CELER, CBRIDGE, DLN, DEBRIDGE, EYWA, HOP, MESON, MULTICHAIN, STARGATE, SYMBIOSIS, SYNAPSE, WORMHOLE, CCIP', - 'PURPOSE': 'BRIDGE' - } } }, - tags = ['gold','defi','bridge','curated','ez'] -) }} - -SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - sender, - receiver, - destination_chain_receiver, - COALESCE( - c.standardized_name, - b.destination_chain - ) AS destination_chain, - destination_chain_id, - token_address, - token_symbol, - amount_unadj, - amount, - ROUND( - CASE - WHEN amount_usd < 1e+15 THEN amount_usd - ELSE NULL - END, - 2 - ) AS amount_usd, - token_is_verified, - COALESCE ( - complete_bridge_activity_id, - {{ dbt_utils.generate_surrogate_key( - ['_id'] - ) }} - ) AS ez_bridge_activity_id, - COALESCE( - inserted_timestamp, - '2000-01-01' - ) AS inserted_timestamp, - COALESCE( - modified_timestamp, - '2000-01-01' - ) AS modified_timestamp -FROM - {{ ref('silver_bridge__complete_bridge_activity') }} - b - LEFT JOIN {{ ref('silver_bridge__standard_chain_seed') }} C - ON b.destination_chain = C.variation diff --git a/models/gold/defi/defi__ez_dex_swaps.sql b/models/gold/defi/defi__ez_dex_swaps.sql deleted file mode 100644 index c0f3bef..0000000 --- a/models/gold/defi/defi__ez_dex_swaps.sql +++ /dev/null @@ -1,80 +0,0 @@ -{{ config( - materialized = 'view', - persist_docs ={ "relation": true, - "columns": true }, - meta={ - 'database_tags':{ - 'table': { - 'PROTOCOL': 'TRADER JOE, WOOFI, GMX, KYBERSWAP, ZYBERSWAP, DODO, FRAX, CAMELOT, UNISWAP, SUSHI, CURVE, BALANCER, HASHFLOW, PANCAKESWAP, RAMSES, MAVERICK, DEXALOT', - 'PURPOSE': 'DEX, SWAPS' - } - } - }, - tags = ['gold','defi','dex','curated','ez'] -) }} - -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - pool_name, - event_name, - amount_in_unadj, - amount_in, - ROUND( - CASE - WHEN token_in <> '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' or not token_in_is_verified - AND ( - amount_out_usd IS NULL - OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_out_usd, 0)) > 0.75 - OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_in_usd, 0)) > 0.75 - ) THEN NULL - ELSE amount_in_usd - END, - 2 - ) AS amount_in_usd, - amount_out_unadj, - amount_out, - ROUND( - CASE - WHEN token_out <> '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' or not token_out_is_verified - AND ( - amount_in_usd IS NULL - OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_in_usd, 0)) > 0.75 - OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_out_usd, 0)) > 0.75 - ) THEN NULL - ELSE amount_out_usd - END, - 2 - ) AS amount_out_usd, - sender, - tx_to, - event_index, - platform, - protocol, - version as protocol_version, - token_in, - token_in_is_verified, - token_out, - token_out_is_verified, - symbol_in, - symbol_out, - COALESCE ( - complete_dex_swaps_id, - {{ dbt_utils.generate_surrogate_key( - ['tx_hash','event_index'] - ) }} - ) AS ez_dex_swaps_id, - COALESCE( - inserted_timestamp, - '2000-01-01' - ) AS inserted_timestamp, - COALESCE( - modified_timestamp, - '2000-01-01' - ) AS modified_timestamp -FROM {{ ref('silver_dex__complete_dex_swaps') }} \ No newline at end of file diff --git a/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql b/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql deleted file mode 100644 index 74c7968..0000000 --- a/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.sql +++ /dev/null @@ -1,104 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'across' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - TRY_TO_NUMBER( - decoded_log :"depositId" :: STRING - ) AS depositId, - decoded_log :"depositor" :: STRING AS depositor, - TRY_TO_NUMBER( - decoded_log :"destinationChainId" :: STRING - ) AS destinationChainId, - decoded_log :"message" :: STRING AS message, - TRY_TO_NUMBER( - decoded_log :"originChainId" :: STRING - ) AS originChainId, - decoded_log :"originToken" :: STRING AS originToken, - TRY_TO_TIMESTAMP( - decoded_log :"quoteTimestamp" :: STRING - ) AS quoteTimestamp, - decoded_log :"recipient" :: STRING AS recipient, - TRY_TO_NUMBER( - decoded_log :"relayerFeePct" :: STRING - ) AS relayerFeePct, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0xafc4df6845a4ab948b492800d3d8a25d538a102a2bc07cd01f1cfa097fddcff6' - AND contract_address = '0xe35e9842fceaca96570b734083f4a58e8f7c5f2a' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - depositor AS sender, - recipient AS receiver, - recipient AS destination_chain_receiver, - destinationChainId AS destination_chain_id, - amount, - depositId AS deposit_id, - message, - originChainId AS origin_chain_id, - originToken AS token_address, - quoteTimestamp AS quote_timestamp, - relayerFeePct AS relayer_fee_pct, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.yml b/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.yml deleted file mode 100644 index bc3537e..0000000 --- a/models/silver/defi/bridge/across/silver_bridge__across_fundsdeposited.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 -models: - - name: silver_bridge__across_fundsdeposited - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql b/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql deleted file mode 100644 index 4e66abb..0000000 --- a/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.sql +++ /dev/null @@ -1,134 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'across-v3' AS NAME, - event_index, - topic_0, - CASE - WHEN topic_0 = '0x32ed1a409ef04c7b0227189c3a103dc5ac10e775a15b785dcc510201f7c25ad3' THEN 'FundsDeposited' - WHEN topic_0 = '0xa123dc29aebf7d0c3322c8eeb5b999e859f39937950ed31056532713d0de396f' THEN 'V3FundsDeposited' - END AS event_name, - topics, - DATA, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - topics [1] :: STRING - ) - ) AS destinationChainId, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - topics [2] :: STRING - ) - ) AS depositId, - CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS depositor, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS inputToken, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS outputToken, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) - ) AS inputAmount, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) - ) AS outputAmount, - TRY_TO_TIMESTAMP( - utils.udf_hex_to_int( - segmented_data [4] :: STRING - ) - ) AS quoteTimestamp, - TRY_TO_TIMESTAMP( - utils.udf_hex_to_int( - segmented_data [5] :: STRING - ) - ) AS fillDeadline, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [6] :: STRING - ) - ) AS exclusivityDeadline, - CONCAT('0x', SUBSTR(segmented_data [7] :: STRING, 25, 40)) AS recipient, - CONCAT('0x', SUBSTR(segmented_data [8] :: STRING, 25, 40)) AS exclusiveRelayer, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [9] :: STRING - ) - ) AS relayerFeePct, - segmented_data [10] :: STRING AS message, - event_removed, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topic_0 IN ( - '0x32ed1a409ef04c7b0227189c3a103dc5ac10e775a15b785dcc510201f7c25ad3', - '0xa123dc29aebf7d0c3322c8eeb5b999e859f39937950ed31056532713d0de396f' - ) - AND contract_address = '0xe35e9842fceaca96570b734083f4a58e8f7c5f2a' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - contract_address AS bridge_address, - NAME AS platform, - depositor AS sender, - recipient AS receiver, - recipient AS destination_chain_receiver, - destinationChainId AS destination_chain_id, - inputAmount AS amount, - inputToken AS token_address, - depositId AS deposit_id, - message, - quoteTimestamp AS quote_timestamp, - relayerFeePct AS relayer_fee_pct, - exclusiveRelayer AS exclusive_relayer, - exclusivityDeadline AS exclusivity_deadline, - fillDeadline AS fill_deadline, - outputAmount AS output_amount, - outputToken AS output_token, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.yml b/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.yml deleted file mode 100644 index ed7d8d3..0000000 --- a/models/silver/defi/bridge/across/silver_bridge__across_v3fundsdeposited.yml +++ /dev/null @@ -1,72 +0,0 @@ -version: 2 -models: - - name: silver_bridge__across_v3fundsdeposited - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - not_null diff --git a/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql b/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql deleted file mode 100644 index 26668e8..0000000 --- a/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.sql +++ /dev/null @@ -1,157 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'allbridge' AS platform, - event_index, - 'TokensSent' AS event_name, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)) AS amount, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS destinationChainId, - origin_from_address AS sender, - origin_from_address AS recipient, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS nonce, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) AS messenger, - tx_succeeded, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] = '0x9cd6008e8d4ebd34fd9d022278fec7f95d133780ecc1a0dea459fae3e9675390' --TokensSent - AND contract_address = '0x9ce3447b58d58e8602b7306316a5ff011b92d189' --Allbridge - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -lp_evt AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_index, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS sender, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS token, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [2] :: STRING)) AS amount, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [3] :: STRING)) AS vUsdAmount, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) AS fee, - tx_succeeded, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] = '0xa930da1d3f27a25892307dd59cec52dd9b881661a0f20364757f83a0da2f6873' --SwappedToVUsd - AND contract_address IN ( - '0x47235cb71107cc66b12af6f8b8a9260ea38472c7', - --USDT LP - '0x690e66fc0f8be8964d40e55ede6aebdfcb8a21df' --USDC LP - ) - AND tx_hash IN ( - SELECT - tx_hash - FROM - base_evt - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - s.block_number, - s.block_timestamp, - s.tx_hash, - s.origin_function_signature, - s.origin_from_address, - s.origin_to_address, - s.contract_address AS bridge_address, - s.event_index, - s.event_name, - s.platform, - lp.amount, - lp.token AS token_address, - s.sender, - s.recipient AS receiver, - C.chain AS destination_chain, - s.destinationChainId AS destination_chain_id, - CASE - WHEN C.chain = 'solana' THEN utils.udf_hex_to_base58(CONCAT('0x', s.segmented_data [1] :: STRING)) - WHEN C.chain = 'stellar' THEN s.segmented_data [1] :: STRING - ELSE CONCAT( - '0x', - SUBSTR( - s.segmented_data [1] :: STRING, - 25, - 40 - ) - ) - END AS destination_chain_receiver, - CASE - WHEN C.chain = 'solana' THEN utils.udf_hex_to_base58(CONCAT('0x', s.segmented_data [3] :: STRING)) - WHEN C.chain = 'stellar' THEN s.segmented_data [3] :: STRING - ELSE CONCAT( - '0x', - SUBSTR( - s.segmented_data [3] :: STRING, - 25, - 40 - ) - ) - END AS destination_chain_token, - s.tx_succeeded, - s._log_id, - s._inserted_timestamp -FROM - base_evt s - INNER JOIN lp_evt lp - ON s.tx_hash = lp.tx_hash - AND s.block_number = lp.block_number - LEFT JOIN {{ ref('silver_bridge__allbridge_chain_id_seed') }} C - ON s.destinationChainId = C.chain_id qualify(ROW_NUMBER() over (PARTITION BY s._log_id -ORDER BY - s._inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.yml b/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.yml deleted file mode 100644 index 9da5849..0000000 --- a/models/silver/defi/bridge/allbridge/silver_bridge__allbridge_tokens_sent.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 -models: - - name: silver_bridge__allbridge_tokens_sent - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql b/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql deleted file mode 100644 index 485a08f..0000000 --- a/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.sql +++ /dev/null @@ -1,241 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'axelar' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - decoded_log :"destinationChain" :: STRING AS destinationChain, - LOWER( - decoded_log :"destinationContractAddress" :: STRING - ) AS destinationContractAddress, - decoded_log :"payload" :: STRING AS payload, - origin_from_address AS recipient, - decoded_log :"payloadHash" :: STRING AS payloadHash, - decoded_log :"sender" :: STRING AS sender, - decoded_log :"symbol" :: STRING AS symbol, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0x7e50569d26be643bda7757722291ec66b1be66d8283474ae3fab5a98f878a7a2' - AND contract_address = '0xe432150cce91c13a887f7d836923d5597add8e31' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -native_gas_paid AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'axelar' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - decoded_log :"destinationChain" :: STRING AS destinationChain, - LOWER( - decoded_log :"destinationAddress" :: STRING - ) AS destinationAddress, - TRY_TO_NUMBER( - decoded_log :"gasFeeAmount" :: STRING - ) AS gasFeeAmount, - decoded_log :"payloadHash" :: STRING AS payloadHash, - decoded_log :"refundAddress" :: STRING AS refundAddress, - decoded_log :"sourceAddress" :: STRING AS sourceAddress, - decoded_log :"symbol" :: STRING AS symbol, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0x999d431b58761213cf53af96262b67a069cbd963499fd8effd1e21556217b841' - AND contract_address = '0x2d5d7d31f671f86c782533cc367f14109a082712' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -transfers AS ( - SELECT - block_number, - tx_hash, - event_index, - contract_address AS token_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_token_transfers') }} - WHERE - from_address = '0xce16f69375520ab01377ce7b88f5ba8c48f8d666' - AND to_address IN ( - '0xe432150cce91c13a887f7d836923d5597add8e31', - '0x0000000000000000000000000000000000000000' - ) - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -FINAL AS ( - SELECT - b.block_number, - b.block_timestamp, - b.origin_function_signature, - b.origin_from_address, - b.origin_to_address, - b.tx_hash, - b.event_index, - b.topic_0, - b.event_name, - b.event_removed, - b.tx_status, - b.contract_address AS bridge_address, - b.name AS platform, - b.origin_from_address AS sender, - CASE - WHEN b.recipient = '0x0000000000000000000000000000000000000000' THEN refundAddress - ELSE b.recipient - END AS receiver, - CASE - WHEN LOWER( - b.destinationChain - ) = 'avalanche' THEN 'avalanche c-chain' - WHEN LOWER( - b.destinationChain - ) = 'binance' THEN 'bnb smart chain mainnet' - WHEN LOWER( - b.destinationChain - ) = 'celo' THEN 'celo mainnet' - WHEN LOWER( - b.destinationChain - ) = 'ethereum' THEN 'ethereum mainnet' - WHEN LOWER( - b.destinationChain - ) = 'fantom' THEN 'fantom opera' - WHEN LOWER( - b.destinationChain - ) = 'polygon' THEN 'polygon mainnet' - ELSE LOWER( - b.destinationChain - ) - END AS destination_chain, - b.destinationContractAddress AS destination_contract_address, - CASE - WHEN destination_chain IN ( - 'arbitrum', - 'avalanche c-chain', - 'base', - 'bnb smart chain mainnet', - 'celo mainnet', - 'ethereum mainnet', - 'fantom opera', - 'filecoin', - 'kava', - 'linea', - 'mantle', - 'moonbeam', - 'optimism', - 'polygon mainnet', - 'scroll' - ) THEN receiver - ELSE destination_contract_address - END AS destination_chain_receiver, - b.amount, - b.payload, - b.payloadHash AS payload_hash, - b.symbol AS token_symbol, - t.token_address, - b._log_id, - b._inserted_timestamp - FROM - base_evt b - INNER JOIN transfers t - ON b.block_number = t.block_number - AND b.tx_hash = t.tx_hash - LEFT JOIN native_gas_paid n - ON n.block_number = b.block_number - AND n.tx_hash = b.tx_hash -) -SELECT - * -FROM - FINAL qualify (ROW_NUMBER() over (PARTITION BY _log_id -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.yml b/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.yml deleted file mode 100644 index 559766e..0000000 --- a/models/silver/defi/bridge/axelar/silver_bridge__axelar_contractcallwithtoken.yml +++ /dev/null @@ -1,74 +0,0 @@ -version: 2 -models: - - name: silver_bridge__axelar_contractcallwithtoken - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql b/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql deleted file mode 100644 index cf99ffd..0000000 --- a/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.sql +++ /dev/null @@ -1,146 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH on_ramp_set AS ( - - SELECT - block_timestamp, - tx_hash, - event_name, - TRY_TO_NUMBER( - decoded_log :destChainSelector :: STRING - ) AS destChainSelector, - chain_name, - decoded_log :onRamp :: STRING AS onRampAddress, - modified_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - INNER JOIN {{ ref('silver_bridge__ccip_chain_seed') }} - ON destChainSelector = chain_selector - WHERE - contract_address = LOWER('0x141fa059441E0ca23ce184B6A78bafD2A517DdE8') -- ccip router - AND topic_0 = '0x1f7d0ec248b80e5c0dde0ee531c4fc8fdb6ce9a2b3d90f560c74acd6a7202f23' -- onrampset - AND tx_succeeded - AND event_removed = FALSE - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -ccip_sent AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - l.origin_function_signature, - l.origin_from_address, - l.origin_to_address, - contract_address, - l.event_name, - l.event_index, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT( - '0x', - segmented_data [13] :: STRING - ) AS message_id, - l.decoded_log, - decoded_log :message :feeToken :: STRING AS fee_token, - TRY_TO_NUMBER( - decoded_log :message :feeTokenAmount :: STRING - ) AS fee_token_amount, - TRY_TO_NUMBER( - decoded_log :message :gasLimit :: STRING - ) AS gas_limit, - TRY_TO_NUMBER( - decoded_log :message :nonce :: STRING - ) AS nonce, - decoded_log :message :receiver :: STRING AS receiver, - decoded_log :message :sender :: STRING AS sender, - TRY_TO_NUMBER( - decoded_log :message :sequenceNumber :: STRING - ) AS sequence_number, - TRY_TO_NUMBER( - decoded_log :message :sourceChainSelector :: STRING - ) AS source_chain_selector, - destChainSelector AS dest_chain_selector, - chain_name, - decoded_log :message :tokenAmounts AS token_amounts, - ARRAY_SIZE( - decoded_log :message :tokenAmounts - ) AS token_amounts_count, - CONCAT( - l.tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - l.modified_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - l - INNER JOIN on_ramp_set - ON onRampAddress = contract_address - WHERE - topic_0 = '0xd0c3c799bf9e2639de44391e7f524d229b2b55f5b1ea94b2bf7da42f7243dddd' -- CCIPSendRequested - AND tx_succeeded - AND event_removed = FALSE - -{% if is_incremental() %} -AND l.modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - C.block_number, - C.block_timestamp, - C.origin_function_signature, - C.origin_from_address, - C.origin_to_address, - C.tx_hash, - C.event_name, - C.event_index, - 'chainlink-ccip' AS platform, - 'v1' AS version, - C.contract_address AS bridge_address, - C.message_id, - C.nonce, - C.receiver, - C.sender, - C.receiver AS destination_chain_receiver, - C.sequence_number, - C.source_chain_selector, - C.dest_chain_selector AS destination_chain_id, - C.chain_name AS destination_chain, - C.gas_limit, - C.fee_token, - -- Divide the fee evenly by the number of tokens in the array - C.fee_token_amount / C.token_amounts_count AS fee_token_amount_per_token, - C.token_amounts_count, - TRY_TO_NUMBER( - tokens.value :amount :: STRING - ) AS amount_unadj, - tokens.value :token :: STRING AS token_address, - C._log_id, - C.modified_timestamp -FROM - ccip_sent C, - LATERAL FLATTEN( - input => C.token_amounts - ) AS tokens -WHERE - token_amounts_count > 0 diff --git a/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml b/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml deleted file mode 100644 index 1c4635a..0000000 --- a/models/silver/defi/bridge/ccip/silver_bridge__ccip_send_requested.yml +++ /dev/null @@ -1,70 +0,0 @@ -version: 2 -models: - - name: silver_bridge__ccip_send_requested - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: MODIFIED_TIMESTAMP - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql b/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql deleted file mode 100644 index 2fce335..0000000 --- a/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.sql +++ /dev/null @@ -1,99 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'celer_cbridge' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - TRY_TO_NUMBER( - decoded_log :"dstChainId" :: STRING - ) AS dstChainId, - TRY_TO_NUMBER( - decoded_log :"maxSlippage" :: STRING - ) AS maxSlippage, - TRY_TO_NUMBER( - decoded_log :"nonce" :: STRING - ) AS nonce, - decoded_log :"receiver" :: STRING AS receiver, - decoded_log :"sender" :: STRING AS sender, - decoded_log :"token" :: STRING AS token, - decoded_log :"transferId" :: STRING AS transferId, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0x89d8051e597ab4178a863a5190407b98abfeff406aa8db90c59af76612e58f01' - AND contract_address IN ( - '0xdd90e5e87a2081dcf0391920868ebc2ffb81a1af', - '0x1619de6b6b20ed217a58d00f37b9d47c7663feca' - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - sender, - receiver, - receiver AS destination_chain_receiver, - amount, - dstChainId AS destination_chain_id, - maxSlippage AS max_slippage, - nonce, - token AS token_address, - transferId AS transfer_id, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.yml b/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.yml deleted file mode 100644 index 7dcd0ce..0000000 --- a/models/silver/defi/bridge/celer/silver_bridge__celer_cbridge_send.yml +++ /dev/null @@ -1,74 +0,0 @@ -version: 2 -models: - - name: silver_bridge__celer_cbridge_send - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql b/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql deleted file mode 100644 index 1e97c96..0000000 --- a/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.sql +++ /dev/null @@ -1,129 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'dln_debridge' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - DATA, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(segmented_data [24] :: STRING, 1, 40)) AS token_address, - decoded_log :"affiliateFee" :: STRING AS affiliateFee, - decoded_log :"metadata" :: STRING AS metadata, - TRY_TO_NUMBER( - decoded_log :"nativeFixFee" :: STRING - ) AS nativeFixFee, - decoded_log :"order" AS order_obj, - decoded_log :"order" :"allowedCancelBeneficiarySrc" :: STRING AS allowedCancelBeneficiarySrc, - decoded_log :"order" :"allowedTakerDst" :: STRING AS allowedTakerDst, - decoded_log :"order" :"externalCall" :: STRING AS externalCall, - TRY_TO_NUMBER( - decoded_log :"order" :"giveAmount" :: STRING - ) AS giveAmount, - TRY_TO_NUMBER( - decoded_log :"order" :"giveChainId" :: STRING - ) AS giveChainId, - decoded_log :"order" :"givePatchAuthoritySrc" :: STRING AS givePatchAuthoritySrc, - decoded_log :"order" :"giveTokenAddress" :: STRING AS giveTokenAddress, - TRY_TO_NUMBER( - decoded_log :"order" :"makerOrderNonce" :: STRING - ) AS makerOrderNonce, - decoded_log :"order" :"makerSrc" :: STRING AS makerSrc, - decoded_log :"order" :"orderAuthorityAddressDst" :: STRING AS orderAuthorityAddressDst, - CONCAT('0x', LEFT(segmented_data [28] :: STRING, 40)) AS receiverDst, - TRY_TO_NUMBER( - decoded_log :"order" :"takeAmount" :: STRING - ) AS takeAmount, - TRY_TO_NUMBER( - decoded_log :"order" :"takeChainId" :: STRING - ) AS takeChainId, - decoded_log :"order" :"takeTokenAddress" :: STRING AS takeTokenAddress, - decoded_log :"orderId" :: STRING AS orderId, - TRY_TO_NUMBER( - decoded_log :"percentFee" :: STRING - ) AS percentFee, - TRY_TO_NUMBER( - decoded_log :"referralCode" :: STRING - ) AS referralCode, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0xfc8703fd57380f9dd234a89dce51333782d49c5902f307b02f03e014d18fe471' --CreatedOrder - AND contract_address = '0xef4fb24ad0916217251f553c0596f8edc630eb66' --Dln: Source - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - origin_from_address AS sender, - receiverDst AS receiver, - CASE - WHEN takeChainId :: STRING = '7565164' THEN utils.udf_hex_to_base58(CONCAT('0x', segmented_data [28] :: STRING)) - ELSE receiverDst - END AS destination_chain_receiver, - giveAmount AS amount, - takeChainId AS destination_chain_id, - CASE - WHEN destination_chain_id :: STRING = '7565164' THEN 'solana' - ELSE NULL - END AS destination_chain, - CASE - WHEN token_address = '0x0000000000000000000000000000000000000000' THEN LOWER('0x82aF49447D8a07e3bd95BD0d56f35241523fBab1') - ELSE token_address - END AS token_address, - decoded_log AS decoded_flat, - order_obj, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.yml b/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.yml deleted file mode 100644 index 21aa4a8..0000000 --- a/models/silver/defi/bridge/dln/silver_bridge__dln_debridge_createdorder.yml +++ /dev/null @@ -1,74 +0,0 @@ -version: 2 -models: - - name: silver_bridge__dln_debridge_createdorder - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql b/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql deleted file mode 100644 index a067f77..0000000 --- a/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.sql +++ /dev/null @@ -1,149 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'eywa' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING IN ( - '0x5566d73d091d945ab32ea023cd1930c0d43aa43bef9aee4cb029775cfc94bdae', - --RequestSent - '0xb5f411fa3c897c9b0b6cd61852278a67e73d885610724a5610a8580d3e94cfdb' - ) --locked - AND contract_address IN ( - '0xece9cf6a8f2768a3b8b65060925b646afeaa5167', - --BridgeV2 - '0xac8f44ceca92b2a4b30360e5bd3043850a0ffcbe', - --PortalV2 - '0xbf0b5d561b986809924f88099c4ff0e6bcce60c9' --PortalV2 - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -requestsent AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - NAME, - event_index, - topic_0, - event_name, - decoded_log :"chainIdTo" :: STRING AS chainIdTo, - decoded_log :"data" :: STRING AS data_requestsent, - decoded_log :"requestId" :: STRING AS requestId, - decoded_log :"to" :: STRING AS to_address, - decoded_log, - event_removed, - tx_status, - _log_id, - _inserted_timestamp - FROM - base_evt - WHERE - topic_0 = '0x5566d73d091d945ab32ea023cd1930c0d43aa43bef9aee4cb029775cfc94bdae' --RequestSent -), -locked AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - NAME, - event_index, - topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - decoded_log :"from" :: STRING AS from_address, - decoded_log :"to" :: STRING AS to_address, - decoded_log :"token" :: STRING AS token, - decoded_log, - event_removed, - tx_status, - _log_id, - _inserted_timestamp - FROM - base_evt - WHERE - topic_0 = '0xb5f411fa3c897c9b0b6cd61852278a67e73d885610724a5610a8580d3e94cfdb' --Locked -) -SELECT - r.block_number, - r.block_timestamp, - r.origin_function_signature, - r.origin_from_address, - r.origin_to_address, - r.tx_hash, - r.event_index, - r.topic_0, - r.event_name, - r.event_removed, - r.tx_status, - r.contract_address AS bridge_address, - r.name AS platform, - l.from_address AS sender, - sender AS receiver, - receiver AS destination_chain_receiver, - l.amount, - r.chainIdTo AS destination_chain_id, - l.token AS token_address, - _log_id, - _inserted_timestamp -FROM - requestsent r - LEFT JOIN locked l USING( - block_number, - tx_hash - ) -WHERE - token_address IS NOT NULL diff --git a/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.yml b/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.yml deleted file mode 100644 index a84d5ed..0000000 --- a/models/silver/defi/bridge/eywa/silver_bridge__eywa_requestsent.yml +++ /dev/null @@ -1,74 +0,0 @@ -version: 2 -models: - - name: silver_bridge__eywa_requestsent - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql b/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql deleted file mode 100644 index b0f8c38..0000000 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.sql +++ /dev/null @@ -1,120 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_contracts AS ( - - SELECT - contract_address, - MAX(block_number) AS block_number - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0xe35dddd4ea75d7e9b3fe93af4f4e40e778c3da4074c9d93e7c6536f1e803c1eb' - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND contract_address NOT IN ( - SELECT - DISTINCT contract_address - FROM - {{ this }} -) -{% endif %} -GROUP BY - 1 -), -function_sigs AS ( - SELECT - '0xe9cdfe51' AS function_sig, - 'ammWrapper' AS function_name -), -inputs AS ( - SELECT - contract_address, - block_number, - function_sig, - function_name, - 0 AS function_input, - CONCAT( - function_sig, - LPAD( - function_input, - 64, - 0 - ) - ) AS DATA - FROM - base_contracts - JOIN function_sigs - ON 1 = 1 -), -contract_reads AS ( - SELECT - contract_address, - block_number, - function_sig, - function_name, - function_input, - DATA, - utils.udf_json_rpc_call( - 'eth_call', - [{ 'to': contract_address, 'from': null, 'data': data }, utils.udf_int_to_hex(block_number) ] - ) AS rpc_request, - live.udf_api( - 'POST', - CONCAT( - '{service}', - '/', - '{Authentication}' - ),{}, - rpc_request, - 'Vault/prod/arbitrum/quicknode/mainnet' - ) AS read_output, - SYSDATE() AS _inserted_timestamp - FROM - inputs -), -reads_flat AS ( - SELECT - read_output, - read_output :data :id :: STRING AS read_id, - read_output :data :result :: STRING AS read_result, - SPLIT( - read_id, - '-' - ) AS read_id_object, - function_sig, - function_name, - function_input, - DATA, - contract_address, - block_number, - _inserted_timestamp - FROM - contract_reads -) -SELECT - read_output, - read_id, - read_result, - read_id_object, - function_sig, - function_name, - function_input, - DATA, - block_number, - contract_address, - CONCAT('0x', SUBSTR(read_result, 27, 40)) AS amm_wrapper_address, - _inserted_timestamp -FROM - reads_flat diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.yml b/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.yml deleted file mode 100644 index 0184c2c..0000000 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_ammwrapper.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 -models: - - name: silver_bridge__hop_ammwrapper - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - CONTRACT_ADDRESS - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: AMM_WRAPPER_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_l2canonicaltoken.sql b/models/silver/defi/bridge/hop/silver_bridge__hop_l2canonicaltoken.sql deleted file mode 100644 index d11ec53..0000000 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_l2canonicaltoken.sql +++ /dev/null @@ -1,119 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_contracts AS ( - - SELECT - contract_address, - amm_wrapper_address, - block_number - FROM - {{ ref('silver_bridge__hop_ammwrapper') }} - -{% if is_incremental() %} -WHERE - amm_wrapper_address NOT IN ( - SELECT - DISTINCT amm_wrapper_address - FROM - {{ this }} - ) -{% endif %} -), -function_sigs AS ( - SELECT - '0x1ee1bf67' AS function_sig, - 'l2CanonicalToken' AS function_name -), -inputs AS ( - SELECT - amm_wrapper_address, - block_number, - function_sig, - function_name, - 0 AS function_input, - CONCAT( - function_sig, - LPAD( - function_input, - 64, - 0 - ) - ) AS DATA - FROM - base_contracts - JOIN function_sigs - ON 1 = 1 -), -contract_reads AS ( - SELECT - amm_wrapper_address, - block_number, - function_sig, - function_name, - function_input, - DATA, - utils.udf_json_rpc_call( - 'eth_call', - [{ 'to': amm_wrapper_address, 'from': null, 'data': data }, utils.udf_int_to_hex(block_number) ] - ) AS rpc_request, - live.udf_api( - 'POST', - CONCAT( - '{service}', - '/', - '{Authentication}' - ),{}, - rpc_request, - 'Vault/prod/arbitrum/quicknode/mainnet' - ) AS read_output, - SYSDATE() AS _inserted_timestamp - FROM - inputs -), -reads_flat AS ( - SELECT - read_output, - read_output :data :id :: STRING AS read_id, - read_output :data :result :: STRING AS read_result, - SPLIT( - read_id, - '-' - ) AS read_id_object, - function_sig, - function_name, - function_input, - DATA, - amm_wrapper_address, - block_number, - _inserted_timestamp - FROM - contract_reads -) -SELECT - read_output, - read_id, - read_result, - read_id_object, - function_sig, - function_name, - function_input, - DATA, - block_number, - contract_address, - amm_wrapper_address, - CASE - WHEN contract_address = '0x25fb92e505f752f730cad0bd4fa17ece4a384266' THEN '0xc5102fe9359fd9a28f877a67e36b0f050d81a3cc' - ELSE CONCAT('0x', SUBSTR(read_result, 27, 40)) - END AS token_address, - _inserted_timestamp -FROM - reads_flat - LEFT JOIN base_contracts USING(amm_wrapper_address) -WHERE - token_address <> '0x' - AND token_address IS NOT NULL diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_l2canonicaltoken.yml b/models/silver/defi/bridge/hop/silver_bridge__hop_l2canonicaltoken.yml deleted file mode 100644 index 0047e44..0000000 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_l2canonicaltoken.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 -models: - - name: silver_bridge__hop_l2canonicaltoken - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - CONTRACT_ADDRESS - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql b/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql deleted file mode 100644 index 76aed1c..0000000 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.sql +++ /dev/null @@ -1,116 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'hop' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - TRY_TO_NUMBER( - decoded_log :"amountOutMin" :: STRING - ) AS amountOutMin, - TRY_TO_NUMBER( - decoded_log :"bonderFee" :: STRING - ) AS bonderFee, - TRY_TO_NUMBER( - decoded_log :"chainId" :: STRING - ) AS chainId, - TRY_TO_TIMESTAMP( - decoded_log :"deadline" :: STRING - ) AS deadline, - TRY_TO_TIMESTAMP( - decoded_log :"index" :: STRING - ) AS INDEX, - decoded_log :"recipient" :: STRING AS recipient, - decoded_log :"transferId" :: STRING AS transferId, - decoded_log :"transferNonce" :: STRING AS transferNonce, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0xe35dddd4ea75d7e9b3fe93af4f4e40e778c3da4074c9d93e7c6536f1e803c1eb' - AND origin_to_address IS NOT NULL - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -hop_tokens AS ( - SELECT - block_number, - contract_address, - amm_wrapper_address, - token_address, - _inserted_timestamp - FROM - {{ ref('silver_bridge__hop_l2canonicaltoken') }} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - amm_wrapper_address, - NAME AS platform, - origin_from_address AS sender, - recipient AS receiver, - receiver AS destination_chain_receiver, - chainId AS destination_chain_id, - token_address, - amount, - amountOutMin AS amount_out_min, - bonderFee AS bonder_fee, - deadline, - INDEX, - transferId AS transfer_id, - transferNonce AS transfer_nonce, - _log_id, - _inserted_timestamp -FROM - base_evt b - LEFT JOIN hop_tokens h USING(contract_address) diff --git a/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.yml b/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.yml deleted file mode 100644 index b522d79..0000000 --- a/models/silver/defi/bridge/hop/silver_bridge__hop_transfersent.yml +++ /dev/null @@ -1,74 +0,0 @@ -version: 2 -models: - - name: silver_bridge__hop_transfersent - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 31 diff --git a/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql b/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql deleted file mode 100644 index c9aa204..0000000 --- a/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.sql +++ /dev/null @@ -1,185 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH token_transfers AS ( - - SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - from_address, - to_address, - raw_amount, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_token_transfers') }} - WHERE - from_address <> '0x0000000000000000000000000000000000000000' - AND to_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -native_transfers AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_from_address, - origin_to_address, - origin_function_signature, - from_address, - to_address, - amount_precise_raw, - CONCAT( - tx_hash :: STRING, - '-', - trace_index :: STRING - ) AS _call_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_native_transfers') }} - WHERE - to_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -{% endif %} -), -all_transfers AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - 'Transfer' AS event_name, - to_address AS bridge_address, - from_address AS sender, - to_address AS receiver, - raw_amount AS amount_unadj, - contract_address AS token_address, - {{ dbt_utils.generate_surrogate_key( - ['_log_id'] - ) }} AS _id, - _inserted_timestamp - FROM - token_transfers - UNION ALL - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - NULL AS event_index, - NULL AS event_name, - to_address AS bridge_address, - from_address AS sender, - to_address AS receiver, - amount_precise_raw AS amount_unadj, - '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' AS token_address, - {{ dbt_utils.generate_surrogate_key( - ['_call_id'] - ) }} AS _id, - _inserted_timestamp - FROM - native_transfers -), -dst_info AS ( - SELECT - block_number, - tx_hash, - topics [1] :: STRING AS encoded_data, - SUBSTR(RIGHT(encoded_data, 12), 1, 4) AS destination_chain_id, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3' - AND topics [0] :: STRING = '0x5ce4019f772fda6cb703b26bce3ec3006eb36b73f1d3a0eb441213317d9f5e9d' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '16 hours' - FROM - {{ this }} -) -{% endif %} -) -SELECT - t.block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - t.tx_hash, - event_index, - event_name, - 'meson' AS platform, - bridge_address, - sender, - receiver, - CASE - WHEN origin_from_address = '0x0000000000000000000000000000000000000000' THEN sender - ELSE origin_from_address - END AS destination_chain_receiver, - amount_unadj, - destination_chain_id, - COALESCE(LOWER(chain), 'other') AS destination_chain, - token_address, - _id, - t._inserted_timestamp -FROM - all_transfers t - INNER JOIN dst_info d - ON t.tx_hash = d.tx_hash - AND t.block_number = d.block_number - LEFT JOIN {{ ref('silver_bridge__meson_chain_id_seed') }} - s - ON d.destination_chain_id :: STRING = RIGHT( - s.short_coin_type, - 4 - ) :: STRING -WHERE - origin_to_address IS NOT NULL qualify (ROW_NUMBER() over (PARTITION BY _id -ORDER BY - t._inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.yml b/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.yml deleted file mode 100644 index 7a4e3df..0000000 --- a/models/silver/defi/bridge/meson/silver_bridge__meson_transfers.yml +++ /dev/null @@ -1,52 +0,0 @@ -version: 2 -models: - - name: silver_bridge__meson_transfers - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_ADDRESS - tests: - - not_null - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.sql b/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.sql deleted file mode 100644 index 14a7e0c..0000000 --- a/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.sql +++ /dev/null @@ -1,88 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'multichain' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - decoded_log :"from" :: STRING AS from_address, - decoded_log :"receiver" :: STRING AS receiver, - decoded_log :"swapoutID" :: STRING AS swapoutID, - TRY_TO_NUMBER( - decoded_log :"toChainID" :: STRING - ) AS toChainID, - decoded_log :"token" :: STRING AS token, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0x0d969ae475ff6fcaf0dcfa760d4d8607244e8d95e9bf426f8d5d69f9a3e525af' - AND contract_address = '0x1633d66ca91ce4d81f63ea047b7b19beb92df7f3' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - LOWER(from_address) AS sender, - LOWER(receiver) AS receiver, - LOWER(receiver) AS destination_chain_receiver, - amount, - toChainID AS destination_chain_id, - token AS token_address, - swapoutID AS swapout_id, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.yml b/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.yml deleted file mode 100644 index 97d9880..0000000 --- a/models/silver/defi/bridge/multichain/silver_bridge__multichain_v7_loganyswapout.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 -models: - - name: silver_bridge__multichain_v7_loganyswapout - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql b/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql deleted file mode 100644 index ee77bfc..0000000 --- a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql +++ /dev/null @@ -1,1114 +0,0 @@ --- depends_on: {{ ref('silver__complete_token_prices') }} --- depends_on: {{ ref('price__ez_asset_metadata') }} -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = ['block_number','platform','version'], - cluster_by = ['block_timestamp::DATE','platform'], - post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_from_address, origin_to_address, origin_function_signature, bridge_address, sender, receiver, destination_chain_receiver, destination_chain_id, destination_chain, token_address, token_symbol), SUBSTRING(origin_function_signature, bridge_address, sender, receiver, destination_chain_receiver, destination_chain, token_address, token_symbol)", - tags = ['silver_bridge','defi','bridge','curated','heal'] -) }} - -WITH across AS ( - - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__across_fundsdeposited') }} - -{% if is_incremental() and 'across' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -across_v3 AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v3' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__across_v3fundsdeposited') }} - -{% if is_incremental() and 'across_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -allbridge_v2 AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v2' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__allbridge_tokens_sent') }} - -{% if is_incremental() and 'allbridge_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -axelar AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - NULL AS destination_chain_id, - destination_chain, - token_address, - token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__axelar_contractcallwithtoken') }} - -{% if is_incremental() and 'axelar' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -celer_cbridge AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__celer_cbridge_send') }} - -{% if is_incremental() and 'celer_cbridge' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -ccip AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount_unadj, - _log_id AS _id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('silver_bridge__ccip_send_requested') }} - -{% if is_incremental() and 'ccip' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -dln_debridge AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__dln_debridge_createdorder') }} - -{% if is_incremental() and 'dln_debridge' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -eywa AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__eywa_requestsent') }} - -{% if is_incremental() and 'eywa' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -hop AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__hop_transfersent') }} - -{% if is_incremental() and 'hop' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -layerzero_v2 AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount_unadj, - _log_id AS _id, - inserted_timestamp AS _inserted_timestamp - FROM - {{ ref('silver_bridge__layerzero_v2') }} - -{% if is_incremental() and 'layerzero_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -meson AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount_unadj, - _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__meson_transfers') }} - -{% if is_incremental() and 'meson' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -multichain AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__multichain_v7_loganyswapout') }} - -{% if is_incremental() and 'multichain' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -stargate AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__stargate_swap') }} - -{% if is_incremental() and 'stargate' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -stargate_v2 AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount_unadj, - _log_id AS _id, - inserted_timestamp AS _inserted_timestamp - FROM - {{ ref('silver_bridge__stargate_v2') }} - -{% if is_incremental() and 'stargate_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -symbiosis AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__symbiosis_synthesizerequest') }} - -{% if is_incremental() and 'symbiosis' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -synapse_tb AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1-tb' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__synapse_token_bridge') }} - -{% if is_incremental() and 'synapse_tb' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -synapse_tbs AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1-tbs' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - NULL AS destination_chain, - token_address, - NULL AS token_symbol, - amount AS amount_unadj, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__synapse_tokenbridgeandswap') }} - -{% if is_incremental() and 'synapse_tbs' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -wormhole AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - 'v1' AS version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id :: STRING AS destination_chain_id, - destination_chain, - token_address, - NULL AS token_symbol, - amount_unadj, - _id, - _inserted_timestamp - FROM - {{ ref('silver_bridge__wormhole_transfers') }} - -{% if is_incremental() and 'wormhole' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -all_protocols AS ( - SELECT - * - FROM - across - UNION ALL - SELECT - * - FROM - across_v3 - UNION ALL - SELECT - * - FROM - allbridge_v2 - UNION ALL - SELECT - * - FROM - axelar - UNION ALL - SELECT - * - FROM - celer_cbridge - UNION ALL - SELECT - * - FROM - ccip - UNION ALL - SELECT - * - FROM - dln_debridge - UNION ALL - SELECT - * - FROM - eywa - UNION ALL - SELECT - * - FROM - hop - UNION ALL - SELECT - * - FROM - layerzero_v2 - UNION ALL - SELECT - * - FROM - meson - UNION ALL - SELECT - * - FROM - multichain - UNION ALL - SELECT - * - FROM - stargate - UNION ALL - SELECT - * - FROM - stargate_v2 - UNION ALL - SELECT - * - FROM - symbiosis - UNION ALL - SELECT - * - FROM - synapse_tb - UNION ALL - SELECT - * - FROM - synapse_tbs - UNION ALL - SELECT - * - FROM - wormhole -), -complete_bridge_activity AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - version, - sender, - receiver, - destination_chain_receiver, - CASE - WHEN CONCAT( - platform, - '-', - version - ) IN ( - 'stargate-v1', - 'wormhole-v1', - 'meson-v1', - 'allbridge-v2', - 'chainlink-ccip-v1', - 'layerzero-v2', - 'stargate-v2' - ) THEN destination_chain_id :: STRING - WHEN d.chain_id IS NULL THEN destination_chain_id :: STRING - ELSE d.chain_id :: STRING - END AS destination_chain_id, - CASE - WHEN CONCAT( - platform, - '-', - version - ) IN ( - 'stargate-v1', - 'wormhole-v1', - 'meson-v1', - 'allbridge-v2', - 'chainlink-ccip-v1', - 'layerzero-v2', - 'stargate-v2' - ) THEN LOWER(destination_chain) - WHEN d.chain IS NULL THEN LOWER(destination_chain) - ELSE LOWER( - d.chain - ) - END AS destination_chain, - b.token_address, - CASE - WHEN platform = 'axelar' THEN COALESCE( - C.token_symbol, - b.token_symbol - ) - ELSE C.token_symbol - END AS token_symbol, - C.token_decimals AS token_decimals, - amount_unadj, - CASE - WHEN C.token_decimals IS NOT NULL THEN (amount_unadj / pow(10, C.token_decimals)) - ELSE amount_unadj - END AS amount, - CASE - WHEN C.token_decimals IS NOT NULL THEN ROUND( - amount * p.price, - 2 - ) - ELSE NULL - END AS amount_usd, - p.is_verified AS token_is_verified, - _id, - b._inserted_timestamp - FROM - all_protocols b - LEFT JOIN {{ ref('silver__contracts') }} C - ON b.token_address = C.contract_address - LEFT JOIN {{ ref('price__ez_prices_hourly') }} - p - ON b.token_address = p.token_address - AND DATE_TRUNC( - 'hour', - block_timestamp - ) = p.hour - LEFT JOIN {{ source( - 'external_gold_defillama', - 'dim_chains' - ) }} - d - ON d.chain_id :: STRING = b.destination_chain_id :: STRING - OR LOWER( - d.chain - ) = LOWER( - b.destination_chain - ) -), - -{% if is_incremental() and var( - 'HEAL_MODEL' -) %} -heal_model AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id, - destination_chain, - t0.token_address, - C.token_symbol AS token_symbol, - C.token_decimals AS token_decimals, - amount_unadj, - CASE - WHEN C.token_decimals IS NOT NULL THEN (amount_unadj / pow(10, C.token_decimals)) - ELSE amount_unadj - END AS amount_heal, - CASE - WHEN C.token_decimals IS NOT NULL THEN amount_heal * p.price - ELSE NULL - END AS amount_usd_heal, - p.is_verified AS token_is_verified, - _id, - t0._inserted_timestamp - FROM - {{ this }} - t0 - LEFT JOIN {{ ref('silver__contracts') }} C - ON t0.token_address = C.contract_address - LEFT JOIN {{ ref('price__ez_prices_hourly') }} - p - ON t0.token_address = p.token_address - AND DATE_TRUNC( - 'hour', - block_timestamp - ) = p.hour - WHERE - CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t1.block_number, - '-', - t1.platform, - '-', - t1.version - ) - FROM - {{ this }} - t1 - WHERE - t1.token_decimals IS NULL - AND t1._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t1.token_address) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t2.block_number, - '-', - t2.platform, - '-', - t2.version - ) - FROM - {{ this }} - t2 - WHERE - t2.amount_usd IS NULL - AND t2._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__complete_token_prices') }} - p - WHERE - p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND p.price IS NOT NULL - AND p.token_address = t2.token_address - AND p.hour = DATE_TRUNC( - 'hour', - t2.block_timestamp - ) - ) - GROUP BY - 1 - ) - ), - newly_verified_tokens as ( - select token_address - from {{ ref('price__ez_asset_metadata') }} - where ifnull(is_verified_modified_timestamp, '1970-01-01' :: TIMESTAMP) > dateadd('day', -10, SYSDATE()) - ), - heal_newly_verified_tokens as ( - SELECT - t0.block_number, - t0.block_timestamp, - t0.origin_from_address, - t0.origin_to_address, - t0.origin_function_signature, - t0.tx_hash, - t0.event_index, - t0.bridge_address, - t0.event_name, - t0.platform, - t0.version, - t0.sender, - t0.receiver, - t0.destination_chain_receiver, - t0.destination_chain_id, - t0.destination_chain, - t0.token_address, - t0.token_symbol, - t0.token_decimals, - t0.amount_unadj, - t0.amount, - CASE - WHEN t0.token_decimals IS NOT NULL THEN t0.amount * p.price - ELSE NULL - END AS amount_usd_heal, - p.is_verified AS token_is_verified, - t0._id, - t0._inserted_timestamp - from {{ this }} t0 - join newly_verified_tokens nv - on t0.token_address = nv.token_address - left join {{ ref('price__ez_prices_hourly')}} p - on t0.token_address = p.token_address - and date_trunc('hour', t0.block_timestamp) = p.hour - ), - {% endif %} - - FINAL AS ( - SELECT - * - FROM - complete_bridge_activity - -{% if is_incremental() and var( - 'HEAL_MODEL' -) %} -UNION ALL -SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id, - destination_chain, - token_address, - token_symbol, - token_decimals, - amount_unadj, - amount_heal AS amount, - amount_usd_heal AS amount_usd, - token_is_verified, - _id, - _inserted_timestamp -FROM - heal_model -UNION ALL -SELECT - * -FROM - heal_newly_verified_tokens -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - bridge_address, - event_name, - platform, - version, - sender, - receiver, - destination_chain_receiver, - destination_chain_id, - destination_chain, - token_address, - token_symbol, - token_decimals, - amount_unadj, - amount, - amount_usd, - IFNULL(token_is_verified, FALSE) AS token_is_verified, - _id, - _inserted_timestamp, - {{ dbt_utils.generate_surrogate_key( - ['_id'] - ) }} AS complete_bridge_activity_id, - SYSDATE() AS inserted_timestamp, - SYSDATE() AS modified_timestamp, - '{{ invocation_id }}' AS _invocation_id -FROM - FINAL -WHERE - destination_chain <> 'arbitrum' qualify (ROW_NUMBER() over (PARTITION BY _id -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.yml b/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.yml deleted file mode 100644 index 3feb9bf..0000000 --- a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.yml +++ /dev/null @@ -1,83 +0,0 @@ -version: 2 -models: - - name: silver_bridge__complete_bridge_activity - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null: - where: PLATFORM NOT IN ('stargate') - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null: - where: VERSION <> 'v1-native' AND PLATFORM NOT IN ('wormhole','meson') - - name: EVENT_NAME - tests: - - not_null: - where: VERSION <> 'v1-native' AND PLATFORM NOT IN ('wormhole','meson') - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN - - not_null - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: PLATFORM - - not_null - - name: VERSION - - not_null - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql b/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql deleted file mode 100644 index 84c3f0c..0000000 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.sql +++ /dev/null @@ -1,134 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_contracts AS ( - - SELECT - tx_hash, - block_number, - block_timestamp, - from_address, - to_address AS contract_address, - concat_ws( - '-', - block_number, - tx_position, - CONCAT( - TYPE, - '_', - trace_address - ) - ) AS _call_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_traces') }} - WHERE - from_address = '0x55bdb4164d28fbaf0898e0ef14a589ac09ac9970' - AND TYPE ILIKE 'create%' - AND tx_succeeded - AND trace_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND to_address NOT IN ( - SELECT - DISTINCT pool_address - FROM - {{ this }} -) -{% endif %} -), -function_sigs AS ( - SELECT - '0xfc0c546a' AS function_sig, - 'token' AS function_name -), -inputs AS ( - SELECT - contract_address, - block_number, - function_sig, - function_name, - 0 AS function_input, - CONCAT( - function_sig, - LPAD( - function_input, - 64, - 0 - ) - ) AS DATA - FROM - base_contracts - JOIN function_sigs - ON 1 = 1 -), -contract_reads AS ( - SELECT - contract_address, - block_number, - function_sig, - function_name, - function_input, - DATA, - utils.udf_json_rpc_call( - 'eth_call', - [{ 'to': contract_address, 'from': null, 'data': data }, utils.udf_int_to_hex(block_number) ] - ) AS rpc_request, - live.udf_api( - 'POST', - CONCAT( - '{service}', - '/', - '{Authentication}' - ),{}, - rpc_request, - 'Vault/prod/arbitrum/quicknode/mainnet' - ) AS read_output, - SYSDATE() AS _inserted_timestamp - FROM - inputs -), -reads_flat AS ( - SELECT - read_output, - read_output :data :id :: STRING AS read_id, - read_output :data :result :: STRING AS read_result, - SPLIT( - read_id, - '-' - ) AS read_id_object, - function_sig, - function_name, - function_input, - DATA, - contract_address, - block_number, - _inserted_timestamp - FROM - contract_reads -) -SELECT - read_output, - read_id, - read_result, - read_id_object, - function_sig, - function_name, - function_input, - DATA, - block_number, - contract_address AS pool_address, - CONCAT('0x', SUBSTR(read_result, 27, 40)) AS token_address, - _inserted_timestamp -FROM - reads_flat diff --git a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.yml b/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.yml deleted file mode 100644 index b8d45f3..0000000 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_createpool.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: 2 -models: - - name: silver_bridge__stargate_createpool - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql b/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql deleted file mode 100644 index 080e173..0000000 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.sql +++ /dev/null @@ -1,122 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - LOWER(token_address) AS token_address - FROM - {{ ref('silver_bridge__stargate_createpool') }} -), -base_evt AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'stargate' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amountSD" :: STRING - ) AS amountSD, - TRY_TO_NUMBER( - decoded_log :"chainId" :: STRING - ) AS chainId, - CASE - WHEN chainId < 100 THEN chainId + 100 - ELSE chainId - END AS destination_chain_id, - TRY_TO_NUMBER( - decoded_log :"dstPoolId" :: STRING - ) AS dstPoolId, - TRY_TO_NUMBER( - decoded_log :"eqFee" :: STRING - ) AS eqFee, - TRY_TO_NUMBER( - decoded_log :"eqReward" :: STRING - ) AS eqReward, - TRY_TO_NUMBER( - decoded_log :"amountSD" :: STRING - ) AS lpFee, - TRY_TO_NUMBER( - decoded_log :"amountSD" :: STRING - ) AS protocolFee, - decoded_log :"from" :: STRING AS from_address, - decoded_log, - token_address, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - d - INNER JOIN pools p - ON d.contract_address = p.pool_address - WHERE - topics [0] :: STRING = '0x34660fc8af304464529f48a778e03d03e4d34bcd5f9b6f0cfbf3cd238c642f7f' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - '0x352d8275aae3e0c2404d9f68f6cee084b5beb3dd' AS bridge_address, - NAME AS platform, - from_address AS sender, - from_address AS receiver, - receiver AS destination_chain_receiver, - amountSD AS amount_unadj, - destination_chain_id, - LOWER(chain_name) AS destination_chain, - dstPoolId AS destination_pool_id, - eqFee AS fee, - eqReward AS reward, - lpFee AS lp_fee, - protocolFee AS protocol_fee, - token_address, - _log_id, - _inserted_timestamp -FROM - base_evt b - LEFT JOIN {{ ref('silver_bridge__stargate_chain_id_seed') }} - s - ON b.destination_chain_id :: STRING = s.chain_id :: STRING diff --git a/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.yml b/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.yml deleted file mode 100644 index 6fecae8..0000000 --- a/models/silver/defi/bridge/stargate/silver_bridge__stargate_swap.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 -models: - - name: silver_bridge__stargate_swap - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql b/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql deleted file mode 100644 index 5909c37..0000000 --- a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.sql +++ /dev/null @@ -1,93 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'symbiosis' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - TRY_TO_NUMBER( - decoded_log :"chainID" :: STRING - ) AS chainID, - decoded_log :"from" :: STRING AS from_address, - decoded_log :"id" :: STRING AS id, - decoded_log :"revertableAddress" :: STRING AS revertableAddress, - decoded_log :"to" :: STRING AS to_address, - decoded_log :"token" :: STRING AS token, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0x31325fe0a1a2e6a5b1e41572156ba5b4e94f0fae7e7f63ec21e9b5ce1e4b3eab' - AND contract_address IN ( - '0x0425841529882628880fbd228ac90606e0c2e09a', - '0x01a3c8e513b758ebb011f7afaf6c37616c9c24d9' - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - from_address AS sender, - to_address AS receiver, - receiver AS destination_chain_receiver, - amount, - chainID AS destination_chain_id, - id, - revertableAddress AS revertable_address, - token AS token_address, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.yml b/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.yml deleted file mode 100644 index 61f9976..0000000 --- a/models/silver/defi/bridge/symbiosis/silver_bridge__symbiosis_synthesizerequest.yml +++ /dev/null @@ -1,74 +0,0 @@ -version: 2 -models: - - name: silver_bridge__symbiosis_synthesizerequest - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql b/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql deleted file mode 100644 index 91d6cfc..0000000 --- a/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.sql +++ /dev/null @@ -1,90 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'synapse' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - TRY_TO_NUMBER( - decoded_log :"chainId" :: STRING - ) AS chainId, - decoded_log :"to" :: STRING AS to_address, - decoded_log :"token" :: STRING AS token, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING IN ( - '0xdc5bad4651c5fbe9977a696aadc65996c468cde1448dd468ec0d83bf61c4b57c', - --redeem - '0xda5273705dbef4bf1b902a131c2eac086b7e1476a8ab0cb4da08af1fe1bd8e3b' --deposit - ) - AND contract_address = '0x6f4e8eba4d337f874ab57478acc2cb5bacdc19c9' - AND origin_to_address IS NOT NULL - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - amount, - origin_from_address AS sender, - to_address AS receiver, - receiver AS destination_chain_receiver, - chainId AS destination_chain_id, - token AS token_address, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.yml b/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.yml deleted file mode 100644 index 845da0f..0000000 --- a/models/silver/defi/bridge/synapse/silver_bridge__synapse_token_bridge.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 -models: - - name: silver_bridge__synapse_token_bridge - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql b/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql deleted file mode 100644 index 12eb97a..0000000 --- a/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.sql +++ /dev/null @@ -1,101 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH base_evt AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'synapse' AS NAME, - event_index, - topics [0] :: STRING AS topic_0, - event_name, - TRY_TO_NUMBER( - decoded_log :"amount" :: STRING - ) AS amount, - TRY_TO_NUMBER( - decoded_log :"chainId" :: STRING - ) AS chainId, - TRY_TO_TIMESTAMP( - decoded_log :"deadline" :: STRING - ) AS deadline, - TRY_TO_NUMBER( - decoded_log :"minDy" :: STRING - ) AS minDy, - decoded_log :"to" :: STRING AS to_address, - decoded_log :"token" :: STRING AS token, - TRY_TO_NUMBER( - decoded_log :"tokenIndexFrom" :: STRING - ) AS tokenIndexFrom, - TRY_TO_NUMBER( - decoded_log :"tokenIndexTo" :: STRING - ) AS tokenIndexTo, - decoded_log, - event_removed, - IFF( - tx_succeeded, - 'SUCCESS', - 'FAIL' - ) AS tx_status, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0x91f25e9be0134ec851830e0e76dc71e06f9dade75a9b84e9524071dbbc319425' - AND contract_address = '0x6f4e8eba4d337f874ab57478acc2cb5bacdc19c9' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - topic_0, - event_name, - event_removed, - tx_status, - contract_address AS bridge_address, - NAME AS platform, - origin_from_address AS sender, - to_address AS receiver, - receiver AS destination_chain_receiver, - amount, - chainId AS destination_chain_id, - token AS token_address, - deadline, - minDy AS min_dy, - tokenIndexFrom AS token_index_from, - tokenIndexTo AS token_index_to, - _log_id, - _inserted_timestamp -FROM - base_evt diff --git a/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.yml b/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.yml deleted file mode 100644 index 204b42a..0000000 --- a/models/silver/defi/bridge/synapse/silver_bridge__synapse_tokenbridgeandswap.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: 2 -models: - - name: silver_bridge__synapse_tokenbridgeandswap - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_INDEX - tests: - - not_null - - name: EVENT_NAME - tests: - - not_null - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: RECEIVER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: AMOUNT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql b/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql deleted file mode 100644 index c6e066a..0000000 --- a/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.sql +++ /dev/null @@ -1,291 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_bridge','defi','bridge','curated'] -) }} - -WITH token_transfers AS ( - - SELECT - tr.block_number, - tr.block_timestamp, - tr.origin_function_signature, - tr.origin_from_address, - tr.origin_to_address, - tr.tx_hash, - event_index, - tr.contract_address, - tr.from_address, - tr.to_address, - raw_amount, - regexp_substr_all(SUBSTR(input_data, 11, len(input_data)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) - ) AS destination_chain_id, - CONCAT( - '0x', - segmented_data [3] :: STRING - ) AS recipient1, - CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS recipient2, - LENGTH( - REGEXP_SUBSTR( - segmented_data [3] :: STRING, - '^(0*)' - ) - ) AS len, - CASE - WHEN len >= 24 THEN recipient2 - ELSE recipient1 - END AS destination_recipient_address, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS token, - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [1] :: STRING)) AS amount, - utils.udf_hex_to_int( - segmented_data [4] :: STRING - ) AS arbiterFee, - utils.udf_hex_to_int( - segmented_data [5] :: STRING - ) AS nonce, - CONCAT( - tr.tx_hash :: STRING, - '-', - tr.event_index :: STRING - ) AS _log_id, - tr.modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_token_transfers') }} - tr - INNER JOIN {{ ref('core__fact_transactions') }} - tx - ON tr.block_number = tx.block_number - AND tr.tx_hash = tx.tx_hash - WHERE - tr.from_address <> '0x0000000000000000000000000000000000000000' - AND tr.to_address = '0x0b2402144bb366a632d14b83f244d2e0e21bd39c' - AND tr.origin_function_signature = '0x0f5287b0' -- tokenTransfer - AND destination_chain_id <> 0 - -{% if is_incremental() %} -AND tr.modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND tr.modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -native_transfers AS ( - SELECT - et.block_number, - et.block_timestamp, - et.tx_hash, - tx.from_address AS origin_from_address, - tx.to_address AS origin_to_address, - tx.origin_function_signature, - et.from_address, - et.to_address, - amount_precise_raw, - regexp_substr_all(SUBSTR(input_data, 11, len(input_data)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) - ) AS destination_chain_id, - CONCAT( - '0x', - segmented_data [1] :: STRING - ) AS recipient1, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS recipient2, - LENGTH( - REGEXP_SUBSTR( - segmented_data [1] :: STRING, - '^(0*)' - ) - ) AS len, - CASE - WHEN len >= 24 THEN recipient2 - ELSE recipient1 - END AS destination_recipient_address, - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) AS arbiterFee, - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) AS nonce, - CONCAT( - et.tx_hash :: STRING, - '-', - et.trace_index :: STRING - ) AS _call_id, - et.modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_native_transfers') }} - et - INNER JOIN {{ ref('core__fact_transactions') }} - tx - ON et.block_number = tx.block_number - AND et.tx_hash = tx.tx_hash - WHERE - et.to_address = '0x0b2402144bb366a632d14b83f244d2e0e21bd39c' - AND tx.origin_function_signature = '0x9981509f' -- wrapAndTransfer - AND destination_chain_id <> 0 - -{% if is_incremental() %} -AND et.modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND et.modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -all_transfers AS ( - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - 'Transfer' AS event_name, - to_address AS bridge_address, - from_address AS sender, - to_address AS receiver, - raw_amount AS amount_unadj, - destination_chain_id, - contract_address AS token_address, - destination_recipient_address, - {{ dbt_utils.generate_surrogate_key( - ['_log_id'] - ) }} AS _id, - _inserted_timestamp - FROM - token_transfers - UNION ALL - SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - NULL AS event_index, - NULL AS event_name, - to_address AS bridge_address, - from_address AS sender, - to_address AS receiver, - amount_precise_raw AS amount_unadj, - destination_chain_id, - '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' AS token_address, - destination_recipient_address, - {{ dbt_utils.generate_surrogate_key( - ['_call_id'] - ) }} AS _id, - _inserted_timestamp - FROM - native_transfers -), -base_near AS ( - SELECT - near_address, - addr_encoded - FROM - {{ source( - 'crosschain_silver', - 'near_address_encoded' - ) }} -) -SELECT - block_number, - block_timestamp, - origin_from_address, - origin_to_address, - origin_function_signature, - tx_hash, - event_index, - event_name, - 'wormhole' AS platform, - bridge_address, - sender, - receiver, - amount_unadj, - destination_chain_id, - chain_name AS destination_chain, - token_address, - destination_recipient_address, - --hex address on the destination chain, requires decoding for non-EVM - more info: https://docs.wormhole.com/wormhole/blockchain-environments/environments - CASE - WHEN destination_chain = 'solana' THEN utils.udf_hex_to_base58(destination_recipient_address) - WHEN destination_chain IN ( - 'injective', - 'sei' - ) THEN utils.udf_hex_to_bech32( - destination_recipient_address, - SUBSTR( - destination_chain, - 1, - 3 - ) - ) - WHEN destination_chain IN ( - 'osmosis', - 'xpla' - ) THEN utils.udf_hex_to_bech32( - destination_recipient_address, - SUBSTR( - destination_chain, - 1, - 4 - ) - ) - WHEN destination_chain IN ( - 'terra', - 'terra2', - 'evmos' - ) THEN utils.udf_hex_to_bech32( - destination_recipient_address, - SUBSTR( - destination_chain, - 1, - 5 - ) - ) - WHEN destination_chain IN ( - 'cosmoshub', - 'kujira' - ) THEN utils.udf_hex_to_bech32( - destination_recipient_address, - SUBSTR( - destination_chain, - 1, - 6 - ) - ) - WHEN destination_chain IN ('near') THEN near_address - WHEN destination_chain IN ('algorand') THEN utils.udf_hex_to_algorand(destination_recipient_address) - WHEN destination_chain IN ('polygon') THEN SUBSTR( - destination_recipient_address, - 1, - 42 - ) - ELSE destination_recipient_address - END AS destination_chain_receiver, - _id, - _inserted_timestamp -FROM - all_transfers t - LEFT JOIN {{ ref('silver_bridge__wormhole_chain_id_seed') }} - s - ON t.destination_chain_id :: STRING = s.wormhole_chain_id :: STRING - LEFT JOIN base_near n - ON t.destination_recipient_address = n.addr_encoded -WHERE - origin_to_address IS NOT NULL qualify (ROW_NUMBER() over (PARTITION BY _id -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.yml b/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.yml deleted file mode 100644 index a8a9960..0000000 --- a/models/silver/defi/bridge/wormhole/silver_bridge__wormhole_transfers.yml +++ /dev/null @@ -1,52 +0,0 @@ -version: 2 -models: - - name: silver_bridge__wormhole_transfers - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_ADDRESS - tests: - - not_null - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: BRIDGE_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - DECIMAL - - FLOAT - - NUMBER - - name: DESTINATION_CHAIN_RECEIVER - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 3 diff --git a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql b/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql deleted file mode 100644 index c20a054..0000000 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.sql +++ /dev/null @@ -1,250 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - full_refresh = false, - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools_registered AS ( - - SELECT - block_number, - block_timestamp, - event_index, - tx_hash, - contract_address, - topics [1] :: STRING AS pool_id, - SUBSTR( - topics [1] :: STRING, - 1, - 42 - ) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp, - ROW_NUMBER() over ( - ORDER BY - pool_address - ) AS row_num - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0x3c13bc30b8e878c53fd2a36b679409c073afd75950be43d8858768e956fbc20e' --PoolRegistered - AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -tokens_registered AS ( - SELECT - block_number, - block_timestamp, - event_index, - tx_hash, - contract_address, - decoded_log :poolId :: STRING AS pool_id, - decoded_log :tokens AS tokens, - tokens [0] :: STRING AS token0, - tokens [1] :: STRING AS token1, - tokens [2] :: STRING AS token2, - tokens [3] :: STRING AS token3, - tokens [4] :: STRING AS token4, - tokens [5] :: STRING AS token5, - tokens [6] :: STRING AS token6, - tokens [7] :: STRING AS token7, - decoded_log :assetManagers AS asset_managers, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - topics [0] :: STRING = '0xf5847d3f2197b16cdcd2098ec95d0905cd1abdaf415f07bb7cef2bba8ac5dec4' --TokensRegistered - AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8' - AND tx_hash IN ( - SELECT - tx_hash - FROM - pools_registered - ) - AND tx_succeeded -), -function_sigs AS ( - SELECT - '0x06fdde03' AS function_sig, - 'name' AS function_name - UNION ALL - SELECT - '0x95d89b41' AS function_sig, - 'symbol' AS function_name - UNION ALL - SELECT - '0x313ce567' AS function_sig, - 'decimals' AS function_name -), -inputs_pools AS ( - SELECT - pool_address, - block_number, - function_sig - FROM - pools_registered - JOIN function_sigs - ON 1 = 1 -), -build_rpc_requests AS ( - SELECT - pool_address, - block_number, - function_sig, - RPAD( - function_sig, - 64, - '0' - ) AS input, - utils.udf_json_rpc_call( - 'eth_call', - [{'to': pool_address, 'from': null, 'data': input}, utils.udf_int_to_hex(block_number)], - concat_ws( - '-', - pool_address, - input, - block_number - ) - ) AS rpc_request, - row_num, - CEIL( - row_num / 250 - ) AS batch_no - FROM - inputs_pools - LEFT JOIN pools_registered USING(pool_address) -), -pool_token_reads AS ({% for item in range(10) %} - ( -SELECT - live.udf_api('POST', CONCAT('{service}', '/', '{Authentication}'),{}, batch_rpc_request, 'Vault/prod/arbitrum/quicknode/mainnet') AS read_output, SYSDATE() AS _inserted_timestamp -FROM - ( -SELECT - ARRAY_AGG(rpc_request) batch_rpc_request -FROM - build_rpc_requests -WHERE - batch_no = {{ item }} + 1 - AND batch_no IN ( -SELECT - DISTINCT batch_no -FROM - build_rpc_requests))) {% if not loop.last %} - UNION ALL - {% endif %} -{% endfor %}), -reads_adjusted AS ( - SELECT - VALUE :id :: STRING AS read_id, - VALUE :result :: STRING AS read_result, - SPLIT( - read_id, - '-' - ) AS read_id_object, - read_id_object [0] :: STRING AS pool_address, - LEFT( - read_id_object [1] :: STRING, - 10 - ) AS function_sig, - read_id_object [2] :: STRING AS block_number, - _inserted_timestamp - FROM - pool_token_reads, - LATERAL FLATTEN( - input => read_output :data - ) -), -pool_details AS ( - SELECT - pool_address, - function_sig, - function_name, - read_result, - regexp_substr_all(SUBSTR(read_result, 3, len(read_result)), '.{64}') AS segmented_output, - _inserted_timestamp - FROM - reads_adjusted - LEFT JOIN function_sigs USING(function_sig) -), -FINAL AS ( - SELECT - pool_address, - MIN( - CASE - WHEN function_name = 'symbol' THEN utils.udf_hex_to_string( - segmented_output [2] :: STRING - ) - END - ) AS pool_symbol, - MIN( - CASE - WHEN function_name = 'name' THEN utils.udf_hex_to_string( - segmented_output [2] :: STRING - ) - END - ) AS pool_name, - MIN( - CASE - WHEN read_result :: STRING = '0x' THEN NULL - ELSE utils.udf_hex_to_int(LEFT(read_result :: STRING, 66)) - END - ) :: INTEGER AS pool_decimals, - MAX(_inserted_timestamp) AS _inserted_timestamp - FROM - pool_details - GROUP BY - 1 -) -SELECT - p.block_number, - p.block_timestamp, - p.event_index, - p.tx_hash, - p.contract_address, - p.pool_id, - f.pool_address, - f.pool_symbol, - f.pool_name, - f.pool_decimals, - t.token0, - t.token1, - t.token2, - t.token3, - t.token4, - t.token5, - t.token6, - t.token7, - t.asset_managers, - p._log_id, - f._inserted_timestamp -FROM - FINAL f - LEFT JOIN pools_registered p - ON f.pool_address = p.pool_address - LEFT JOIN tokens_registered t - ON p.pool_id = t.pool_id -WHERE - t.token0 IS NOT NULL diff --git a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.yml b/models/silver/defi/dex/balancer/silver_dex__balancer_pools.yml deleted file mode 100644 index 8657119..0000000 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_pools.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: 2 -models: - - name: silver_dex__balancer_pools - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - - - - \ No newline at end of file diff --git a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql b/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql deleted file mode 100644 index dde8acf..0000000 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.sql +++ /dev/null @@ -1,98 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_name, - pool_address - FROM - {{ ref('silver_dex__balancer_pools') }} -), -swaps_base AS ( - SELECT - tx_hash, - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'Swap' AS event_name, - event_index, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) - ) AS amount_in_unadj, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) - ) AS amount_out_unadj, - topics [1] :: STRING AS pool_id, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token_in, - CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS token_out, - SUBSTR( - topics [1] :: STRING, - 1, - 42 - ) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp, - 'balancer' AS platform, - origin_from_address AS sender, - origin_from_address AS tx_to - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b' - AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - tx_hash, - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - pool_id, - s.pool_address AS contract_address, - pool_name, - event_name, - platform, - _log_id, - _inserted_timestamp -FROM - swaps_base s - INNER JOIN pools p - ON p.pool_address = s.pool_address diff --git a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.yml b/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.yml deleted file mode 100644 index 0cf331f..0000000 --- a/models/silver/defi/dex/balancer/silver_dex__balancer_swaps.yml +++ /dev/null @@ -1,66 +0,0 @@ -version: 2 -models: - - name: silver_dex__balancer_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _log_id - columns: - - name: AMOUNT_IN_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: AMOUNT_OUT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: EVENT_INDEX - tests: - - not_null - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: POOL_NAME - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - varchar - - name: SENDER - tests: - - not_null - - name: TX_TO - tests: - - not_null - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql b/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql deleted file mode 100644 index b4da44b..0000000 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_pools.sql +++ /dev/null @@ -1,67 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address IN ( - '0x6eccab422d763ac031210895c81787e87b43a652', - --v2 - '0xd490f2f6990c0291597fd1247651b4e0dcf684dd', - '0x1a3c9b1d2f0529d97f2afc5136cc23e58f1fd35b' - ) --v3 - AND topics [0] :: STRING IN ( - '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9', - --PairCreated v2 - '0x91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db' - ) --v3 - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_pools.yml b/models/silver/defi/dex/camelot/silver_dex__camelot_pools.yml deleted file mode 100644 index a544896..0000000 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__camelot_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.sql b/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.sql deleted file mode 100644 index 6ff5b55..0000000 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.sql +++ /dev/null @@ -1,124 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__camelot_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) :: INTEGER - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INTEGER - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) :: INTEGER - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) :: INTEGER - ) AS amount1Out, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender, - tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'camelot-v2' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.yml b/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.yml deleted file mode 100644 index cd2a6f6..0000000 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_v2_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__camelot_v2_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.sql b/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.sql deleted file mode 100644 index befb4b1..0000000 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.sql +++ /dev/null @@ -1,122 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__camelot_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS reipient_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [0] :: STRING - ) - ) AS amount0, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [1] :: STRING - ) - ) AS amount1, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS price, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS liquidity, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [4] :: STRING - ) - ) AS tick, - ABS(GREATEST(amount0, amount1)) AS amountOut, - ABS(LEAST(amount0, amount1)) AS amountIn, - token0, - token1, - CASE - WHEN amount0 < 0 THEN token0 - ELSE token1 - END AS token_in, - CASE - WHEN amount0 > 0 THEN token0 - ELSE token1 - END AS token_out, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender_address AS sender, - reipient_address AS tx_to, - amount0, - amount1, - price, - liquidity, - tick, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - token_in, - token_out, - 'Swap' AS event_name, - 'camelot-v3' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base diff --git a/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.yml b/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.yml deleted file mode 100644 index 7742693..0000000 --- a/models/silver/defi/dex/camelot/silver_dex__camelot_v3_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__camelot_v3_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/curve/silver_dex__curve_pools.sql b/models/silver/defi/dex/curve/silver_dex__curve_pools.sql deleted file mode 100644 index e2c230b..0000000 --- a/models/silver/defi/dex/curve/silver_dex__curve_pools.sql +++ /dev/null @@ -1,441 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - full_refresh = false, - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH contract_deployments AS ( - - SELECT - tx_hash, - block_number, - block_timestamp, - from_address AS deployer_address, - to_address AS contract_address, - concat_ws( - '-', - block_number, - tx_position, - CONCAT( - TYPE, - '_', - trace_address - ) - ) AS _call_id, - modified_timestamp AS _inserted_timestamp, - ROW_NUMBER() over ( - ORDER BY - contract_address - ) AS row_num - FROM - {{ ref( - 'core__fact_traces' - ) }} - WHERE - -- curve contract deployers - from_address IN ( - '0x7eeac6cddbd1d0b8af061742d41877d7f707289a', - '0x745748bcfd8f9c2de519a71d789be8a63dd7d66c', - '0xbabe61887f1de2713c6f97e567623453d3c79f67', - '0xb17b674d9c5cb2e441f8e196a2f048a81355d031' - ) - AND TYPE ILIKE 'create%' - AND tx_succeeded - AND trace_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} - -qualify(ROW_NUMBER() over(PARTITION BY to_address -ORDER BY - block_timestamp ASC)) = 1 -), -function_sigs AS ( - SELECT - '0x87cb4f57' AS function_sig, - 'base_coins' AS function_name - UNION ALL - SELECT - '0xb9947eb0' AS function_sig, - 'underlying_coins' AS function_name - UNION ALL - SELECT - '0xc6610657' AS function_sig, - 'coins' AS function_name - UNION ALL - SELECT - '0x06fdde03' AS function_sig, - 'name' AS function_name - UNION ALL - SELECT - '0x95d89b41' AS function_sig, - 'symbol' AS function_name - UNION ALL - SELECT - '0x313ce567' AS function_sig, - 'decimals' AS function_name -), -function_inputs AS ( - SELECT - SEQ4() AS function_input - FROM - TABLE(GENERATOR(rowcount => 8)) -), -inputs_coins AS ( - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - (ROW_NUMBER() over (PARTITION BY contract_address - ORDER BY - block_number)) - 1 AS function_input - FROM - contract_deployments - JOIN function_sigs - ON 1 = 1 - JOIN function_inputs - ON 1 = 1 - WHERE - function_name = 'coins' -), -inputs_base_coins AS ( - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - (ROW_NUMBER() over (PARTITION BY contract_address - ORDER BY - block_number)) - 1 AS function_input - FROM - contract_deployments - JOIN function_sigs - ON 1 = 1 - JOIN function_inputs - ON 1 = 1 - WHERE - function_name = 'base_coins' -), -inputs_underlying_coins AS ( - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - (ROW_NUMBER() over (PARTITION BY contract_address - ORDER BY - block_number)) - 1 AS function_input - FROM - contract_deployments - JOIN function_sigs - ON 1 = 1 - JOIN function_inputs - ON 1 = 1 - WHERE - function_name = 'underlying_coins' -), -inputs_pool_details AS ( - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - NULL AS function_input - FROM - contract_deployments - JOIN function_sigs - ON 1 = 1 - WHERE - function_name IN ( - 'name', - 'symbol', - 'decimals' - ) -), -all_inputs AS ( - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - function_input - FROM - inputs_coins - UNION ALL - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - function_input - FROM - inputs_base_coins - UNION ALL - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - function_input - FROM - inputs_underlying_coins - UNION ALL - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - function_input - FROM - inputs_pool_details -), -build_rpc_requests AS ( - SELECT - deployer_address, - contract_address, - block_number, - function_sig, - function_input, - CONCAT( - function_sig, - LPAD(IFNULL(function_input, 0), 64, '0') - ) AS input, - utils.udf_json_rpc_call( - 'eth_call', - [{'to': contract_address, 'from': null, 'data':input }, utils.udf_int_to_hex(block_number)], - concat_ws( - '-', - contract_address, - input, - block_number - ) - ) AS rpc_request, - row_num, - CEIL( - row_num / 5 - ) AS batch_no - FROM - all_inputs - LEFT JOIN contract_deployments USING(contract_address) -), -pool_token_reads AS ( - -{% if is_incremental() %} -{% for item in range(6) %} - ( - SELECT - live.udf_api('POST', CONCAT('{service}', '/', '{Authentication}'),{}, batch_rpc_request, 'Vault/prod/arbitrum/quicknode/mainnet') AS read_output, SYSDATE() AS _inserted_timestamp - FROM - ( - SELECT - ARRAY_AGG(rpc_request) batch_rpc_request - FROM - build_rpc_requests - WHERE - batch_no = {{ item }} + 1 - AND batch_no IN ( - SELECT - DISTINCT batch_no - FROM - build_rpc_requests))) {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} -{% else %} - {% for item in range(60) %} - ( - SELECT - live.udf_api('POST', CONCAT('{service}', '/', '{Authentication}'),{}, batch_rpc_request, 'Vault/prod/arbitrum/quicknode/mainnet') AS read_output, SYSDATE() AS _inserted_timestamp - FROM - ( - SELECT - ARRAY_AGG(rpc_request) batch_rpc_request - FROM - build_rpc_requests - WHERE - batch_no = {{ item }} + 1 - AND batch_no IN ( - SELECT - DISTINCT batch_no - FROM - build_rpc_requests))) {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} -{% endif %}), -reads_adjusted AS ( - SELECT - VALUE :id :: STRING AS read_id, - VALUE :result :: STRING AS read_result, - SPLIT( - read_id, - '-' - ) AS read_id_object, - read_id_object [0] :: STRING AS contract_address, - read_id_object [2] :: STRING AS block_number, - LEFT( - read_id_object [1] :: STRING, - 10 - ) AS function_sig, - RIGHT( - read_id_object [1], - LENGTH( - read_id_object [1] - 10 - ) - ) :: INT AS function_input, - _inserted_timestamp - FROM - pool_token_reads, - LATERAL FLATTEN( - input => read_output :data - ) -), -tokens AS ( - SELECT - contract_address, - function_sig, - function_name, - function_input, - read_result, - regexp_substr_all(SUBSTR(read_result, 3, len(read_result)), '.{64}') [0] AS segmented_token_address, - _inserted_timestamp - FROM - reads_adjusted - LEFT JOIN function_sigs USING(function_sig) - WHERE - function_name IN ( - 'coins', - 'base_coins', - 'underlying_coins' - ) - AND read_result IS NOT NULL -), -pool_details AS ( - SELECT - contract_address, - function_sig, - function_name, - function_input, - read_result, - regexp_substr_all(SUBSTR(read_result, 3, len(read_result)), '.{64}') AS segmented_output, - _inserted_timestamp - FROM - reads_adjusted - LEFT JOIN function_sigs USING(function_sig) - WHERE - function_name IN ( - 'name', - 'symbol', - 'decimals' - ) - AND read_result IS NOT NULL -), -all_pools AS ( - SELECT - t.contract_address AS pool_address, - CONCAT('0x', SUBSTRING(t.segmented_token_address, 25, 40)) AS token_address, - function_input AS token_id, - function_name AS token_type, - MIN( - CASE - WHEN p.function_name = 'symbol' THEN utils.udf_hex_to_string(RTRIM(p.segmented_output [2] :: STRING, 0)) - END - ) AS pool_symbol, - MIN( - CASE - WHEN p.function_name = 'name' THEN CONCAT( - utils.udf_hex_to_string( - p.segmented_output [2] :: STRING - ), - utils.udf_hex_to_string( - segmented_output [3] :: STRING - ) - ) - END - ) AS pool_name, - MIN( - CASE - WHEN p.read_result :: STRING = '0x' THEN NULL - ELSE ethereum.public.udf_hex_to_int(LEFT(p.read_result :: STRING, 66)) - END - ) :: INTEGER AS pool_decimals, - CONCAT( - t.contract_address, - '-', - CONCAT('0x', SUBSTRING(t.segmented_token_address, 25, 40)), - '-', - function_input, - '-', - function_name - ) AS pool_id, - MAX( - t._inserted_timestamp - ) AS _inserted_timestamp - FROM - tokens t - LEFT JOIN pool_details p USING(contract_address) - WHERE - token_address IS NOT NULL - AND token_address <> '0x0000000000000000000000000000000000000000' - GROUP BY - 1, - 2, - 3, - 4 -), -FINAL AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - deployer_address, - pool_address, - CASE - WHEN token_address = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE token_address - END AS token_address, - token_id, - token_type, - CASE - WHEN token_address = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN 'WETH' - WHEN pool_symbol IS NULL THEN C.token_symbol - ELSE pool_symbol - END AS pool_symbol, - pool_name, - CASE - WHEN token_address = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '18' - WHEN pool_decimals IS NULL THEN C.token_decimals - ELSE pool_decimals - END AS pool_decimals, - pool_id, - _call_id, - A._inserted_timestamp - FROM - all_pools A - LEFT JOIN {{ ref('silver__contracts') }} C - ON A.token_address = C.contract_address - LEFT JOIN contract_deployments d - ON A.pool_address = d.contract_address qualify(ROW_NUMBER() over(PARTITION BY pool_address, token_address - ORDER BY - A._inserted_timestamp DESC)) = 1 -) -SELECT - *, - ROW_NUMBER() over ( - PARTITION BY pool_address - ORDER BY - token_address ASC - ) AS token_num -FROM - FINAL diff --git a/models/silver/defi/dex/curve/silver_dex__curve_pools.yml b/models/silver/defi/dex/curve/silver_dex__curve_pools.yml deleted file mode 100644 index 1ba35ef..0000000 --- a/models/silver/defi/dex/curve/silver_dex__curve_pools.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: 2 -models: - - name: silver_dex__curve_pools - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ID - columns: - - name: POOL_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - varchar - - name: TOKEN_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - varchar - - name: POOL_SYMBOL - - name: POOL_NAME - - name: POOL_DECIMALS - - name: _INSERTED_TIMESTAMP \ No newline at end of file diff --git a/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql b/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql deleted file mode 100644 index 00941e1..0000000 --- a/models/silver/defi/dex/curve/silver_dex__curve_swaps.sql +++ /dev/null @@ -1,257 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_meta AS ( - - SELECT - DISTINCT pool_address, - pool_name, - token_address, - pool_symbol AS symbol, - token_id :: INTEGER AS token_id, - token_type :: STRING AS token_type - FROM - {{ ref('silver_dex__curve_pools') }} -), -pools AS ( - SELECT - DISTINCT pool_address, - pool_name - FROM - pool_meta qualify (ROW_NUMBER() over (PARTITION BY pool_address - ORDER BY - pool_name ASC nulls last)) = 1 -), -curve_base AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_index, - CASE - WHEN topics [0] :: STRING = '0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b' THEN 'TokenExchangeUnderlying' - ELSE 'TokenExchange' - END AS event_name, - contract_address AS pool_address, - pool_name, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) - ) AS sold_id, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) - ) AS tokens_sold, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) - ) AS bought_id, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) - ) AS tokens_bought, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - topics [0] :: STRING IN ( - '0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140', - '0xb2e76ae99761dc136e598d4a629bb347eccb9532a5f8bbd72e18467c3c34cc98', - '0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b' - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -token_exchange AS ( - SELECT - _log_id, - MAX( - CASE - WHEN sold_id = token_id THEN token_address - END - ) AS token_in, - MAX( - CASE - WHEN bought_id = token_id THEN token_address - END - ) AS token_out, - MAX( - CASE - WHEN sold_id = token_id THEN symbol - END - ) AS symbol_in, - MAX( - CASE - WHEN bought_id = token_id THEN symbol - END - ) AS symbol_out - FROM - curve_base t - LEFT JOIN pool_meta p - ON p.pool_address = t.pool_address - AND ( - p.token_id = t.sold_id - OR p.token_id = t.bought_id - ) - WHERE - token_type = 'coins' - GROUP BY - 1 -), -token_transfers AS ( - SELECT - tx_hash, - contract_address AS token_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - DATA :: STRING - ) - ) AS amount, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS from_address, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS to_address - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' - AND tx_hash IN ( - SELECT - DISTINCT tx_hash - FROM - curve_base - ) - AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) <> '0x0000000000000000000000000000000000000000' - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -from_transfers AS ( - SELECT - DISTINCT tx_hash, - token_address, - from_address, - amount - FROM - token_transfers -), -to_transfers AS ( - SELECT - DISTINCT tx_hash, - token_address, - to_address, - amount - FROM - token_transfers -), -ready_pool_info AS ( - SELECT - s.block_number, - s.block_timestamp, - s.tx_hash, - s.origin_function_signature, - s.origin_from_address, - s.origin_from_address AS tx_to, - s.origin_to_address, - event_index, - event_name, - pool_address, - pool_address AS contract_address, - pool_name, - sender, - sold_id, - tokens_sold, - COALESCE( - sold.token_address, - e.token_in - ) AS token_in, - e.symbol_in AS symbol_in, - bought_id, - tokens_bought, - COALESCE( - bought.token_address, - e.token_out - ) AS token_out, - e.symbol_out AS symbol_out, - s._log_id, - _inserted_timestamp - FROM - curve_base s - LEFT JOIN token_exchange e - ON s._log_id = e._log_id - LEFT JOIN from_transfers sold - ON tokens_sold = sold.amount - AND s.tx_hash = sold.tx_hash - LEFT JOIN to_transfers bought - ON tokens_bought = bought.amount - AND s.tx_hash = bought.tx_hash - WHERE - tokens_sold <> 0 qualify(ROW_NUMBER() over(PARTITION BY s._log_id - ORDER BY - _inserted_timestamp DESC)) = 1 -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - tx_to, - origin_to_address, - event_index, - event_name, - pool_address, - contract_address, - pool_name, - sender, - sold_id, - tokens_sold, - token_in, - symbol_in, - bought_id, - tokens_bought, - token_out, - symbol_out, - _log_id, - _inserted_timestamp, - 'curve' AS platform -FROM - ready_pool_info diff --git a/models/silver/defi/dex/curve/silver_dex__curve_swaps.yml b/models/silver/defi/dex/curve/silver_dex__curve_swaps.yml deleted file mode 100644 index 906b6c4..0000000 --- a/models/silver/defi/dex/curve/silver_dex__curve_swaps.yml +++ /dev/null @@ -1,54 +0,0 @@ -version: 2 -models: - - name: silver_dex__curve_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _log_id - columns: - - name: TOKENS_SOLD - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: TOKENS_BOUGHT - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: EVENT_INDEX - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: POOL_NAME - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - varchar - - name: SENDER - tests: - - not_null - - name: TX_TO - tests: - - not_null - - name: TOKEN_IN - - name: TOKEN_OUT - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/dexalot/silver_dex__dexalot_swaps.sql b/models/silver/defi/dex/dexalot/silver_dex__dexalot_swaps.sql deleted file mode 100644 index d731db3..0000000 --- a/models/silver/defi/dex/dexalot/silver_dex__dexalot_swaps.sql +++ /dev/null @@ -1,91 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH base_swaps AS ( - - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - topic_1 AS nouceAndMeta, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS taker, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS destTrader, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [2] :: STRING - ) - ) AS destChainId, - CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS srcAsset, - CONCAT('0x', SUBSTR(segmented_data [4] :: STRING, 25, 40)) AS destAsset, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [5] :: STRING - ) - ) AS srcAmount, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [6] :: STRING - ) - ) AS destAmount, - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address = '0x010224949cca211fb5ddfedd28dc8bf9d2990368' - AND topic_0 = '0x68eb6d948c037c94e470f9a5b288dd93debbcd9342635408e66cb0211686f7f7' - AND destChainId = 42161 - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX( - modified_timestamp - ) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'SwapExecuted' AS event_name, - srcAmount AS amount_in_unadj, - destAmount AS amount_out_unadj, - srcAsset AS token_in, - destAsset AS token_out, - origin_from_address AS sender, - taker AS recipient, - destTrader AS tx_to, - event_index, - 'dexalot' AS platform, - _log_id, - modified_timestamp -FROM - base_swaps diff --git a/models/silver/defi/dex/dexalot/silver_dex__dexalot_swaps.yml b/models/silver/defi/dex/dexalot/silver_dex__dexalot_swaps.yml deleted file mode 100644 index 63c3673..0000000 --- a/models/silver/defi/dex/dexalot/silver_dex__dexalot_swaps.yml +++ /dev/null @@ -1,93 +0,0 @@ -version: 2 -models: - - name: silver_dex__dexalot_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT \ No newline at end of file diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql deleted file mode 100644 index 20f2ab5..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.sql +++ /dev/null @@ -1,58 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_events AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS newBorn, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS baseToken, - CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS quoteToken, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = '0xbcc3401e16c25eaf4d3fed632ce3288503883b1f' --DODOZoo - AND topics [0] :: STRING = '0x5c428a2e12ecaa744a080b25b4cda8b86359c82d726575d7d747e07708071f93' --DODOBirth - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - newBorn AS pool_address, - baseToken AS base_token, - quoteToken AS quote_token, - _log_id AS _id, - _inserted_timestamp -FROM - pool_events qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.yml b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.yml deleted file mode 100644 index babc118..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_pools.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: 2 -models: - - name: silver_dex__dodo_v1_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql deleted file mode 100644 index 020dd68..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.sql +++ /dev/null @@ -1,187 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - base_token, - quote_token - FROM - {{ ref('silver_dex__dodo_v1_pools') }} -), -proxies AS ( - SELECT - '0xd5a7e197bace1f3b26e2760321d6ce06ad07281a' AS proxy_address - UNION - SELECT - '0x8ab2d334ce64b50be9ab04184f7ccba2a6bb6391' AS proxy_address -), -sell_base_token AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS seller_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS payBase, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS receiveQuote, - base_token, - quote_token, - quote_token AS tokenIn, - base_token AS tokenOut, - receiveQuote AS amountIn, - payBase AS amountOut, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - topics [0] :: STRING = '0xd8648b6ac54162763c86fd54bf2005af8ecd2f9cb273a5775921fd7f91e17b2d' --sellBaseToken - AND seller_address NOT IN ( - SELECT - proxy_address - FROM - proxies - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -buy_base_token AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS buyer_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS receiveBase, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS payQuote, - base_token, - quote_token, - quote_token AS tokenIn, - base_token AS tokenOut, - payQuote AS amountIn, - receiveBase AS amountOut, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - topics [0] :: STRING = '0xe93ad76094f247c0dafc1c61adc2187de1ac2738f7a3b49cb20b2263420251a3' --buyBaseToken - AND buyer_address NOT IN ( - SELECT - proxy_address - FROM - proxies - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - seller_address AS sender, - origin_from_address AS tx_to, - tokenIn AS token_in, - tokenOut AS token_out, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - 'SellBaseToken' AS event_name, - 'dodo-v1' AS platform, - _log_id, - _inserted_timestamp -FROM - sell_base_token -UNION ALL -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - buyer_address AS sender, - origin_from_address AS tx_to, - tokenIn AS token_in, - tokenOut AS token_out, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - 'BuyBaseToken' AS event_name, - 'dodo-v1' AS platform, - _log_id, - _inserted_timestamp -FROM - buy_base_token diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.yml b/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.yml deleted file mode 100644 index 258f4f6..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v1_swaps.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: 2 -models: - - name: silver_dex__dodo_v1_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: AMOUNT_IN_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: AMOUNT_OUT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: EVENT_INDEX - tests: - - not_null - - name: SENDER - tests: - - not_null - - name: TX_TO - tests: - - not_null - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql deleted file mode 100644 index 9fac061..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.sql +++ /dev/null @@ -1,77 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS baseToken, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS quoteToken, - CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS creator, - CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address IN ( - '0xa6cf3d163358af376ec5e8b7cc5e102a05fde63d', - '0xddb13e6dd168e1a68dc2285cb212078ae10394a9', - --dpp - factory, - '0x7b07164ecfaf0f0d85dfc062bc205a4674c75aa0', - '0x1506b54a1c0ea1b2f4a84866ec5776f7f6e7f0b1', - --dpp oracle - '0x9340e3296121507318874ce9c04afb4492af0284', - '0xc8fe2440744dcd733246a4db14093664defd5a53', - --dsp - factory - '0xda4c4411c55b0785e501332354a036c04833b72b' --dvm - factory - ) - AND topics [0] :: STRING IN ( - '0x8494fe594cd5087021d4b11758a2bbc7be28a430e94f2b268d668e5991ed3b8a', - --NewDPP - '0xbc1083a2c1c5ef31e13fb436953d22b47880cf7db279c2c5666b16083afd6b9d', - --NewDSP - '0xaf5c5f12a80fc937520df6fcaed66262a4cc775e0f3fceaf7a7cfe476d9a751d' --NewDVM - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - baseToken AS base_token, - quoteToken AS quote_token, - creator, - pool_address, - _log_id, - _inserted_timestamp -FROM - pools qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.yml b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.yml deleted file mode 100644 index 857a7ae..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_pools.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: 2 -models: - - name: silver_dex__dodo_v2_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql deleted file mode 100644 index b091355..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.sql +++ /dev/null @@ -1,128 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - DISTINCT pool_address - FROM - {{ ref('silver_dex__dodo_v2_pools') }} -), -proxies AS ( - SELECT - '0xd5a7e197bace1f3b26e2760321d6ce06ad07281a' AS proxy_address - UNION - SELECT - '0x8ab2d334ce64b50be9ab04184f7ccba2a6bb6391' AS proxy_address -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [0] :: STRING, - 25, - 40 - ) - ) AS fromToken, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [1] :: STRING, - 25, - 40 - ) - ) AS toToken, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS fromAmount, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS toAmount, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [4] :: STRING, - 25, - 40 - ) - ) AS trader_address, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [5] :: STRING, - 25, - 40 - ) - ) AS receiver_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON l.contract_address = p.pool_address - WHERE - l.topics [0] :: STRING = '0xc2c0245e056d5fb095f04cd6373bc770802ebd1e6c918eb78fdef843cdb37b0f' --dodoswap - AND trader_address NOT IN ( - SELECT - proxy_address - FROM - proxies - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - fromToken AS token_in, - toToken AS token_out, - fromAmount AS amount_in_unadj, - toAmount AS amount_out_unadj, - trader_address AS sender, - receiver_address AS tx_to, - 'DodoSwap' AS event_name, - 'dodo-v2' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base diff --git a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.yml b/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.yml deleted file mode 100644 index cf3c991..0000000 --- a/models/silver/defi/dex/dodo/silver_dex__dodo_v2_swaps.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: 2 -models: - - name: silver_dex__dodo_v2_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: AMOUNT_IN_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: AMOUNT_OUT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: EVENT_INDEX - tests: - - not_null - - name: SENDER - tests: - - not_null - - name: TX_TO - tests: - - not_null - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql deleted file mode 100644 index 21330cd..0000000 --- a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.sql +++ /dev/null @@ -1,66 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address AS factory_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INT AS pool_id, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address IN ( - '0x5ca135cb8527d76e932f34b5145575f9d8cbe08e', - --v1 factory - '0x8374a74a728f06bea6b7259c68aa7bbb732bfead' --v2 factory - ) - AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --pairCreated - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - factory_address, - event_index, - token0, - token1, - pool_address, - pool_id, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.yml b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.yml deleted file mode 100644 index 919de94..0000000 --- a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__fraxswap_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.sql b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.sql deleted file mode 100644 index 2f061b4..0000000 --- a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.sql +++ /dev/null @@ -1,125 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__fraxswap_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS amount1Out, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools - ON l.contract_address = pool_address - WHERE - l.topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' --Swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - sender_address AS sender, - to_address AS tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'fraxswap' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.yml b/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.yml deleted file mode 100644 index 61da9bd..0000000 --- a/models/silver/defi/dex/fraxswap/silver_dex__fraxswap_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__fraxswap_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.sql b/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.sql deleted file mode 100644 index 84f28d0..0000000 --- a/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.sql +++ /dev/null @@ -1,109 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH swaps_base AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT( - '0x', - SUBSTR( - segmented_data [0] :: STRING, - 25, - 40 - ) - ) AS account_address, - CONCAT( - '0x', - SUBSTR( - segmented_data [1] :: STRING, - 25, - 40 - ) - ) AS tokenIn, - CONCAT( - '0x', - SUBSTR( - segmented_data [2] :: STRING, - 25, - 40 - ) - ) AS tokenOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) - ) AS amountIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [4] :: STRING - ) - ) AS amountOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [5] :: STRING - ) - ) AS amountOutAfterFees, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [6] :: STRING - ) - ) AS feeBasisPoints, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address = '0x489ee077994b6658eafa855c308275ead8097c4a' - AND topics [0] :: STRING = '0x0874b2d545cb271cdbda4e093020c452328b24af12382ed62c4d00f5c26709db' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - origin_from_address AS sender, - account_address AS tx_to, - tokenIn AS token_in, - tokenOut AS token_out, - amountIn AS amount_in_unadj, - amountOutAfterFees AS amount_out_unadj, - 'Swap' AS event_name, - 'gmx' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base diff --git a/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.yml b/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.yml deleted file mode 100644 index 6ac60cb..0000000 --- a/models/silver/defi/dex/gmx/silver_dex__gmx_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__gmx_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/gmx/silver_dex__gmx_v2_swaps.sql b/models/silver/defi/dex/gmx/silver_dex__gmx_v2_swaps.sql deleted file mode 100644 index 1feb42f..0000000 --- a/models/silver/defi/dex/gmx/silver_dex__gmx_v2_swaps.sql +++ /dev/null @@ -1,174 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH decoded_logs AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - topics, - DATA, - event_index, - decoded_log, - decoded_log :eventName :: STRING AS event_name, - decoded_log :eventNameHash :: STRING AS event_name_hash, - decoded_log :msgSender :: STRING AS msg_sender, - decoded_log :topic1 :: STRING AS topic_1, - decoded_log :topic2 :: STRING AS topic_2, - decoded_log :eventData AS event_data, - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__ez_decoded_event_logs') }} - WHERE - contract_address = '0xc8ee91a54287db53897056e12d9819156d3822fb' - AND decoded_log :eventName :: STRING IN ( - 'SwapInfo', - 'OrderExecuted' - ) - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX( - modified_timestamp - ) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -parse_data AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_index, - _log_id, - modified_timestamp, - event_name, - event_name_hash, - msg_sender, - topic_1, - topic_2, - event_data [0] [0] [0] [1] :: STRING AS market, - event_data [0] [0] [1] [1] :: STRING AS receiver, - event_data [0] [0] [2] [1] :: STRING AS token_in, - event_data [0] [0] [3] [1] :: STRING AS token_out, - TRY_TO_NUMBER( - event_data [1] [0] [0] [1] :: STRING - ) AS token_in_price, - TRY_TO_NUMBER( - event_data [1] [0] [1] [1] :: STRING - ) AS token_out_price, - TRY_TO_NUMBER( - event_data [1] [0] [2] [1] :: STRING - ) AS amount_in, - TRY_TO_NUMBER( - event_data [1] [0] [3] [1] :: STRING - ) AS amount_in_after_fees, - TRY_TO_NUMBER( - event_data [1] [0] [4] [1] :: STRING - ) AS amount_out, - TRY_TO_NUMBER( - event_data [2] [0] [0] [1] :: STRING - ) AS price_impact_usd, - TRY_TO_NUMBER( - event_data [2] [0] [0] [1] :: STRING - ) AS price_impact_amount, - event_data [4] [0] [0] [1] :: STRING AS key - FROM - decoded_logs - WHERE - event_name = 'SwapInfo' -), -column_format AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - p.contract_address, - event_index, - _log_id, - modified_timestamp, - event_name, - event_name_hash, - msg_sender AS sender, - receiver AS tx_to, - topic_1, - market, - receiver, - token_in, - token_in_price AS raw_token_in_price, - amount_in AS amount_in_unadj, - amount_in_after_fees, - token_out, - token_out_price AS raw_token_out_price, - amount_out AS amount_out_unadj, - price_impact_usd, - price_impact_amount, - key - FROM - parse_data p -), -executed_orders AS ( - SELECT - event_data [4] [0] [0] [1] :: STRING AS key - FROM - decoded_logs - WHERE - event_name = 'OrderExecuted' -) -SELECT - A.block_number, - A.block_timestamp, - A.tx_hash, - A.origin_function_signature, - A.origin_from_address, - A.origin_to_address, - A.contract_address, - A.event_index, - market, - receiver, - sender, - tx_to, - CASE - WHEN e.key IS NOT NULL THEN 'executed' - ELSE 'not-executed' - END AS order_execution, - token_in, - amount_in_unadj, - token_out, - amount_out_unadj, - 'gmx-v2' AS platform, - 'Swap' AS event_name, - A.key, - A._log_id, - A.modified_timestamp -FROM - column_format A - INNER JOIN executed_orders e - ON A.key = e.key diff --git a/models/silver/defi/dex/gmx/silver_dex__gmx_v2_swaps.yml b/models/silver/defi/dex/gmx/silver_dex__gmx_v2_swaps.yml deleted file mode 100644 index f7971fb..0000000 --- a/models/silver/defi/dex/gmx/silver_dex__gmx_v2_swaps.yml +++ /dev/null @@ -1,85 +0,0 @@ -version: 2 -models: - - name: silver_dex__gmx_v2_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql deleted file mode 100644 index 6c5cefb..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.sql +++ /dev/null @@ -1,67 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH contract_deployments AS ( - - SELECT - tx_hash, - block_number, - block_timestamp, - from_address AS deployer_address, - to_address AS contract_address, - concat_ws( - '-', - block_number, - tx_position, - CONCAT( - TYPE, - '_', - trace_address - ) - ) AS _call_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_traces') }} - WHERE - from_address IN ( - '0xe43632337d3f9a52ffd098fe71a57cc5961c041f', - '0x63ae536fec0b57bdeb1fd6a893191b4239f61bff', - '0x75fb2ab4d5b0de8b1a1acdc9124887d35d459084' - ) - AND TYPE ILIKE 'create%' - AND tx_succeeded - AND trace_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND to_address NOT IN ( - SELECT - DISTINCT pool_address - FROM - {{ this }} -) -{% endif %} - -qualify(ROW_NUMBER() over(PARTITION BY to_address -ORDER BY - block_timestamp ASC)) = 1 -) -SELECT - tx_hash, - block_number, - block_timestamp, - deployer_address, - contract_address AS pool_address, - _call_id, - _inserted_timestamp -FROM - contract_deployments diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.yml b/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.yml deleted file mode 100644 index 3cabb93..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_pools.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 -models: - - name: silver_dex__hashflow_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.sql deleted file mode 100644 index c234b3f..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.sql +++ /dev/null @@ -1,229 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address - FROM - {{ ref('silver_dex__hashflow_pools') }} -), -router_swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [1] :: STRING, - 25, - 40 - ) - ) AS account_address, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [3] :: STRING, - 25, - 40 - ) - ) AS tokenIn, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [4] :: STRING, - 25, - 40 - ) - ) AS tokenOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [5] :: STRING - ) - ) AS amountIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [6] :: STRING - ) - ) AS amountOut, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON l.contract_address = p.pool_address - WHERE - l.topics [0] :: STRING = '0xb709ddcc6550418e9b89df1f4938071eeaa3f6376309904c77e15d46b16066f5' --swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [0] :: STRING, - 25, - 40 - ) - ) AS account_address, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [2] :: STRING, - 25, - 40 - ) - ) AS tokenIn, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [3] :: STRING, - 25, - 40 - ) - ) AS tokenOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [4] :: STRING - ) - ) AS amountIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [5] :: STRING - ) - ) AS amountOut, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON l.contract_address = p.pool_address - WHERE - l.topics [0] :: STRING = '0x8cf3dec1929508e5677d7db003124e74802bfba7250a572205a9986d86ca9f1e' --swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -FINAL AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - origin_from_address AS sender, - account_address AS tx_to, - tokenIn AS token_in, - tokenOut AS token_out, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - 'Swap' AS event_name, - 'hashflow' AS platform, - _log_id, - _inserted_timestamp - FROM - router_swaps_base - UNION ALL - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - origin_from_address AS sender, - account_address AS tx_to, - tokenIn AS token_in, - tokenOut AS token_out, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - 'Swap' AS event_name, - 'hashflow' AS platform, - _log_id, - _inserted_timestamp - FROM - swaps_base -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - sender, - tx_to, - CASE - WHEN token_in = '0x0000000000000000000000000000000000000000' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE token_in - END AS token_in, - CASE - WHEN token_out = '0x0000000000000000000000000000000000000000' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE token_out - END AS token_out, - amount_in_unadj, - amount_out_unadj, - event_name, - platform, - _log_id, - _inserted_timestamp -FROM - FINAL diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.yml b/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.yml deleted file mode 100644 index 12b547b..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__hashflow_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_NTZ - - TIMESTAMP_LTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql deleted file mode 100644 index d724bc8..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.sql +++ /dev/null @@ -1,52 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "pool_address", - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH contract_deployments AS ( - - SELECT - tx_hash, - block_number, - block_timestamp, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - origin_from_address AS deployer_address, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0xdE828fdc3F497F16416D1bB645261C7C6a62DAb5') - AND topics [0] :: STRING = '0xdbd2a1ea6808362e6adbec4db4969cbc11e3b0b28fb6c74cb342defaaf1daada' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - tx_hash, - block_number, - block_timestamp, - deployer_address, - pool_address, - _log_id, - _inserted_timestamp -FROM - contract_deployments qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.yml b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.yml deleted file mode 100644 index bac858e..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_pools.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 -models: - - name: silver_dex__hashflow_v3_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql deleted file mode 100644 index e803cc5..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.sql +++ /dev/null @@ -1,98 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = "block_number", - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address - FROM - {{ ref('silver_dex__hashflow_v3_pools') }} -), -swaps AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - l.origin_function_signature, - l.origin_from_address, - l.origin_to_address, - l.event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS trader_address, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS effective_trader_address, - CONCAT( - '0x', - segmented_data [2] :: STRING - ) AS txid, - CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS tokenIn, - CONCAT('0x', SUBSTR(segmented_data [4] :: STRING, 25, 40)) AS tokenOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [5] :: STRING - ) - ) AS amountIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [6] :: STRING - ) - ) AS amountOut, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON l.contract_address = p.pool_address - WHERE - l.topics [0] :: STRING = '0x34f57786fb01682fb4eec88d340387ef01a168fe345ea5b76f709d4e560c10eb' --Trade - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - effective_trader_address AS sender, - trader_address AS tx_to, - txid, - CASE - WHEN tokenIn = '0x0000000000000000000000000000000000000000' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE tokenIn - END AS token_in, - CASE - WHEN tokenOut = '0x0000000000000000000000000000000000000000' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE tokenOut - END AS token_out, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - 'Trade' AS event_name, - 'hashflow-v3' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps diff --git a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.yml b/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.yml deleted file mode 100644 index 2cf0d44..0000000 --- a/models/silver/defi/dex/hashflow/silver_dex__hashflow_v3_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__hashflow_v3_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_NTZ - - TIMESTAMP_LTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql deleted file mode 100644 index f9398ca..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) - ) AS ampBps, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) - ) AS totalPool, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0xD9bfE9979e9CA4b2fe84bA5d4Cf963bBcB376974') --dynamic fee factory - AND topics [0] :: STRING = '0xfc574402c445e75f2b79b67884ff9c662244dce454c5ae68935fcd0bebb7c8ff' --created pool - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - ampBps AS amp_bps, - totalPool AS total_pool, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.yml b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.yml deleted file mode 100644 index d4decd5..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_pools.yml +++ /dev/null @@ -1,24 +0,0 @@ -version: 2 -models: - - name: silver_dex__kyberswap_v1_dynamic_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql deleted file mode 100644 index 61f04d6..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.sql +++ /dev/null @@ -1,131 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__kyberswap_v1_dynamic_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS amount1Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [4] :: STRING - ) - ) AS feeInPrecision, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - l.topics [0] :: STRING = '0x606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c2499' --Dynamic Swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - sender_address AS sender, - to_address AS tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - feeInPrecision AS fee_in_precision, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Dynamic Swap' AS event_name, - 'kyberswap-v1' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.yml b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.yml deleted file mode 100644 index 949b8cd..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_dynamic_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__kyberswap_v1_dynamic_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql deleted file mode 100644 index da3fb93..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.sql +++ /dev/null @@ -1,76 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) - ) AS ampBps, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) - ) AS feeUnits, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) - ) AS totalPool, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0x1c758aF0688502e49140230F6b0EBd376d429be5') --static pool factory - AND topics [0] :: STRING = '0xb6bce363b712c921bead4bcc977289440eb6172eb89e258e3a25bd49ca806de6' --create pool - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - ampBps AS amp_bps, - feeUnits AS fee_units, - totalPool AS total_pool, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.yml b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.yml deleted file mode 100644 index 23845d1..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__kyberswap_v1_static_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql deleted file mode 100644 index c5f4478..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.sql +++ /dev/null @@ -1,131 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__kyberswap_v1_static_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS amount1Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [4] :: STRING - ) - ) AS feeInPrecision, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - l.topics [0] :: STRING = '0x606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c2499' -- static swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - sender_address AS sender, - to_address AS tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - feeInPrecision AS fee_in_precision, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Static Swap' AS event_name, - 'kyberswap-v1' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.yml b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.yml deleted file mode 100644 index 599527f..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v1_static_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__kyberswap_v1_static_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql deleted file mode 100644 index 867e9aa..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.sql +++ /dev/null @@ -1,69 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - TRY_TO_NUMBER(utils.udf_hex_to_int(topics [3] :: STRING)) AS swapFeeUnits, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) - ) AS tickDistance, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address IN ( - '0x5f1dddbf348ac2fbe22a163e30f99f9ece3dd50a', - '0xc7a590291e07b9fe9e64b86c58fd8fc764308c4a' - ) --KyberSwap: Elastic Factory - AND topics [0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' --Create pool - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - swapFeeUnits AS swap_fee_units, - tickDistance AS tick_distance, - pool_address, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.yml b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.yml deleted file mode 100644 index ce90af1..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__kyberswap_v2_elastic_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql deleted file mode 100644 index 8ded91a..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.sql +++ /dev/null @@ -1,126 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__kyberswap_v2_elastic_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS reipient_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [0] :: STRING - ) - ) AS deltaQty0, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [1] :: STRING - ) - ) AS deltaQty1, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS sqrtP, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS liquidity, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [4] :: STRING - ) - ) AS currentTick, - ABS(GREATEST(deltaQty0, deltaQty1)) AS amountOut, - ABS(LEAST(deltaQty0, deltaQty1)) AS amountIn, - token0, - token1, - CASE - WHEN deltaQty0 < 0 THEN token0 - ELSE token1 - END AS token_in, - CASE - WHEN deltaQty0 > 0 THEN token0 - ELSE token1 - END AS token_out, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' -- elastic swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - sender_address AS sender, - reipient_address AS tx_to, - deltaQty0 AS delta_qty0, - deltaQty1 AS delta_qty1, - sqrtP AS sqrt_p, - liquidity, - currentTick AS current_tick, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - token0, - token1, - token_in, - token_out, - 'Elastic Swap' AS event_name, - 'kyberswap-v2' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.yml b/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.yml deleted file mode 100644 index 2340577..0000000 --- a/models/silver/defi/dex/kyberswap/silver_dex__kyberswap_v2_elastic_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__kyberswap_v2_elastic_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_pools.sql b/models/silver/defi/dex/maverick/silver_dex__maverick_v2_pools.sql deleted file mode 100644 index c1cdc5c..0000000 --- a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_pools.sql +++ /dev/null @@ -1,130 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH created_pools AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [1] :: STRING - ) - ) AS protocolFeeRatio, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [2] :: STRING - ) - ) AS feeAIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [3] :: STRING - ) - ) AS feeBIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [4] :: STRING - ) - ) AS tickSpacing, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [5] :: STRING - ) - ) AS lookback, - -- lookback period - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [6] :: STRING - ) - ) AS activetick, - -- pool type (static/right/left/both/all) - CONCAT( - '0x', - SUBSTR( - segmented_data [7] :: STRING, - 25, - 40 - ) - ) AS tokenA, - CONCAT( - '0x', - SUBSTR( - segmented_data [8] :: STRING, - 25, - 40 - ) - ) AS tokenB, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [9] :: STRING - ) - ) AS kinds, - CONCAT( - '0x', - SUBSTR( - segmented_data [10] :: STRING, - 25, - 40 - ) - ) AS accessor, - -- null if permissionless pool - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0x0A7e848Aca42d879EF06507Fca0E7b33A0a63c1e') --factory - AND topic_0 = '0x848331e408557f4b7eb6561ca1c18a3ac43004fbe64b8b5bce613855cfdf22d2' --paircreated - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - protocolFeeRatio AS protocol_fee_ratio, - feeAin, - feeBin, - tickspacing AS tick_spacing, - lookback, - activetick, - tokenA, - tokenB, - kinds, - accessor, - _log_id, - modified_timestamp -FROM - created_pools qualify(ROW_NUMBER() over(PARTITION BY pool_address -ORDER BY - modified_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_pools.yml b/models/silver/defi/dex/maverick/silver_dex__maverick_v2_pools.yml deleted file mode 100644 index a806e4b..0000000 --- a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_pools.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: 2 -models: - - name: silver_dex__maverick_v2_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKENA - tests: - - not_null - - name: TOKENB - tests: - - not_null - - name: KINDS - tests: - - not_null - - name: TICK_SPACING - tests: - - not_null - - name: feeAin - tests: - - not_null - - name: feeBin - tests: - - not_null diff --git a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_swaps.sql b/models/silver/defi/dex/maverick/silver_dex__maverick_v2_swaps.sql deleted file mode 100644 index 05510a7..0000000 --- a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_swaps.sql +++ /dev/null @@ -1,136 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - tokenA, - tokenB - FROM - {{ ref('silver_dex__maverick_v2_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [0] :: STRING, - 25, - 40 - ) - ) AS sender_address, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [1] :: STRING, - 25, - 40 - ) - ) AS recipient_address, - CASE - WHEN TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) = 0 THEN FALSE - ELSE TRUE - END AS tokenAin, - CASE - WHEN TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [4] :: STRING - ) - ) = 0 THEN FALSE - ELSE TRUE - END AS exactOutput, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [5] :: STRING - ) - ) AS activetick, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [6] :: STRING - ) - ) AS amountIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [7] :: STRING - ) - ) AS amountOut, - tokenA, - tokenB, - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools - ON l.contract_address = pool_address - WHERE - l.topic_0 :: STRING = '0x103ed084e94a44c8f5f6ba8e3011507c41063177e29949083c439777d8d63f60' --Swap - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - contract_address AS pool_address, - sender_address AS sender, - recipient_address AS tx_to, - tokenAin AS token_A_in, - exactOutput AS exact_output, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - activetick, - CASE - WHEN token_A_in = TRUE THEN tokenA - ELSE tokenB - END AS token_in, - CASE - WHEN token_A_in = TRUE THEN tokenB - ELSE tokenA - END AS token_out, - 'Swap' AS event_name, - 'maverick-v2' AS platform, - _log_id, - modified_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_swaps.yml b/models/silver/defi/dex/maverick/silver_dex__maverick_v2_swaps.yml deleted file mode 100644 index e9b0d25..0000000 --- a/models/silver/defi/dex/maverick/silver_dex__maverick_v2_swaps.yml +++ /dev/null @@ -1,98 +0,0 @@ -version: 2 -models: - - name: silver_dex__maverick_v2_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - number - - float - - name: AMOUNT_OUT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - number - - float \ No newline at end of file diff --git a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_pools.sql b/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_pools.sql deleted file mode 100644 index 9e1b6eb..0000000 --- a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_pools.sql +++ /dev/null @@ -1,72 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH created_pools AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0_address, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - topics [3] :: STRING - ) - ) AS fee, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) - ) AS tickSpacing, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address = '0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865' --factory - AND topic_0 = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' --paircreated - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - token0_address, - token1_address, - fee :: INTEGER AS fee, - ( - fee / 10000 - ) :: FLOAT AS fee_percent, - tickSpacing AS tick_spacing, - pool_address, - _log_id, - modified_timestamp -FROM - created_pools qualify(ROW_NUMBER() over(PARTITION BY pool_address -ORDER BY - modified_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_pools.yml b/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_pools.yml deleted file mode 100644 index 65df6cf..0000000 --- a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_pools.yml +++ /dev/null @@ -1,46 +0,0 @@ -version: 2 -models: - - name: silver_dex__pancakeswap_v3_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 7 - - name: FEE - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: POOL_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN0_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN1_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_HASH - tests: - - not_null - - - diff --git a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_swaps.sql b/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_swaps.sql deleted file mode 100644 index d4a8418..0000000 --- a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_swaps.sql +++ /dev/null @@ -1,155 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0_address, - token1_address, - fee, - tick_spacing - FROM - {{ ref('silver_dex__pancakeswap_v3_pools') }} -), -base_swaps AS ( - SELECT - l.block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - l.block_timestamp, - l.tx_hash, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS recipient_address, - COALESCE( - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) - ), - 0 - ) AS amount0, - COALESCE( - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [1] :: STRING - ) - ), - 0 - ) AS amount1, - COALESCE( - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) - ), - 0 - ) AS sqrtPriceX96, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) - ) AS liquidity, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [4] :: STRING - ) - ) AS tick, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [5] :: STRING - ) - ) AS protocolFeesToken0, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - segmented_data [6] :: STRING - ) - ) AS protocolFeesToken1, - ABS(LEAST(amount0, amount1)) AS amount_out_unadj, - ABS(GREATEST(amount0, amount1)) AS amount_in_unadj, - token0_address, - token1_address, - CASE - WHEN amount0 > 0 THEN token0_address - ELSE token1_address - END AS token_in, - CASE - WHEN amount1 < 0 THEN token1_address - ELSE token0_address - END AS token_out, - fee, - tick_spacing, - CONCAT( - l.tx_hash, - '-', - l.event_index - ) AS _log_id, - l.modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON l.contract_address = pool_address - WHERE - block_timestamp :: DATE > '2023-06-01' - AND topic_0 = '0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83' --swap - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - 'pancakeswap-v3' AS platform, - 'v3' AS version, - contract_address, - contract_address AS pool_address, - sender_address AS sender, - recipient_address AS tx_to, - event_index, - 'Swap' AS event_name, - amount0, - amount1, - sqrtPriceX96, - liquidity, - tick, - tick_spacing, - fee, - protocolFeesToken0, - protocolFeesToken1, - amount_out_unadj, - amount_in_unadj, - token0_address, - token1_address, - token_in, - token_out, - _log_id, - modified_timestamp -FROM - base_swaps diff --git a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_swaps.yml b/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_swaps.yml deleted file mode 100644 index 4657f4e..0000000 --- a/models/silver/defi/dex/pancakeswap/silver_dex__pancakeswap_v3_swaps.yml +++ /dev/null @@ -1,67 +0,0 @@ -version: 2 -models: - - name: silver_dex__pancakeswap_v3_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: AMOUNT_OUT_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: AMOUNT_IN_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: LIQUIDITY - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: EVENT_INDEX - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: SENDER - tests: - - not_null - - name: TX_TO - tests: - - not_null - - name: TICK - tests: - - not_null - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql deleted file mode 100644 index 7795a79..0000000 --- a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.sql +++ /dev/null @@ -1,108 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - cluster_by = ['_inserted_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH created_pools AS ( - - SELECT - block_number AS created_block, - block_timestamp AS created_time, - tx_hash AS created_tx_hash, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - LOWER(CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))) AS token0_address, - LOWER(CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))) AS token1_address, - utils.udf_hex_to_int( - 's2c', - topics [3] :: STRING - ) :: INTEGER AS fee, - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) :: INTEGER AS tick_spacing, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' - AND contract_address = LOWER('0xAA2cd7477c451E703f3B9Ba5663334914763edF8') - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -initial_info AS ( - SELECT - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS init_sqrtPriceX96, - utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [1] :: STRING)) :: FLOAT AS init_tick, - pow( - 1.0001, - init_tick - ) AS init_price_1_0_unadj - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -FINAL AS ( - SELECT - created_block, - created_time, - created_tx_hash, - p.contract_address, - token0_address, - token1_address, - fee :: INTEGER AS fee, - ( - fee / 10000 - ) :: FLOAT AS fee_percent, - tick_spacing, - pool_address, - COALESCE( - init_tick, - 0 - ) AS init_tick, - p._log_id, - p._inserted_timestamp - FROM - created_pools p - LEFT JOIN initial_info i - ON p.pool_address = i.contract_address -) -SELECT - * -FROM - FINAL qualify(ROW_NUMBER() over(PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.yml b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.yml deleted file mode 100644 index d6d7608..0000000 --- a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_pools.yml +++ /dev/null @@ -1,37 +0,0 @@ -version: 2 -models: - - name: silver_dex__ramses_v2_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: CREATED_BLOCK - tests: - - not_null - - name: CREATED_TIME - tests: - - not_null - - name: FEE - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: INIT_TICK - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: TICK_SPACING - tests: - - not_null - - name: CREATED_TX_HASH - tests: - - not_null - - - diff --git a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql deleted file mode 100644 index 4bb3453..0000000 --- a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.sql +++ /dev/null @@ -1,100 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH base_swaps AS ( - - SELECT - *, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS recipient, - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) :: FLOAT AS amount0_unadj, - utils.udf_hex_to_int( - 's2c', - segmented_data [1] :: STRING - ) :: FLOAT AS amount1_unadj, - utils.udf_hex_to_int( - 's2c', - segmented_data [2] :: STRING - ) :: FLOAT AS sqrtPriceX96, - utils.udf_hex_to_int( - 's2c', - segmented_data [3] :: STRING - ) :: FLOAT AS liquidity, - utils.udf_hex_to_int( - 's2c', - segmented_data [4] :: STRING - ) :: FLOAT AS tick - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_succeeded - AND event_removed = 'false' - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -pool_data AS ( - SELECT - token0_address, - token1_address, - fee, - fee_percent, - tick_spacing, - pool_address - FROM - {{ ref('silver_dex__ramses_v2_pools') }} -), -FINAL AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address AS pool_address, - recipient, - sender, - fee, - tick, - tick_spacing, - liquidity, - event_index, - token0_address, - token1_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - amount0_unadj, - amount1_unadj - FROM - base_swaps - INNER JOIN pool_data - ON pool_data.pool_address = base_swaps.contract_address -) -SELECT - * -FROM - FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.yml b/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.yml deleted file mode 100644 index 3a1b040..0000000 --- a/models/silver/defi/dex/ramses/silver_dex__ramses_v2_swaps.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: 2 -models: - - name: silver_dex__ramses_v2_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: AMOUNT0_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: AMOUNT1_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: LIQUIDITY - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: EVENT_INDEX - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: RECIPIENT - tests: - - not_null - - name: SENDER - tests: - - not_null - - name: TICK - tests: - - not_null - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.sql b/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.sql deleted file mode 100644 index b6e3ce0..0000000 --- a/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.sql +++ /dev/null @@ -1,1597 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = ['block_number','platform','version'], - cluster_by = ['block_timestamp::DATE','platform'], - post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, contract_address, pool_address, pool_name, tokens, symbols), SUBSTRING(pool_address, pool_name, tokens, symbols)", - tags = ['silver_dex','defi','dex','curated','heal'] -) }} - -WITH contracts AS ( - - SELECT - contract_address, - token_symbol, - token_decimals, - _inserted_timestamp - FROM - {{ ref('silver__contracts') }} -), -balancer AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - token2, - token3, - token4, - token5, - token6, - token7, - 'balancer' AS platform, - 'v1' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__balancer_pools') }} - -{% if is_incremental() and 'balancer' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -curve AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - deployer_address AS contract_address, - pool_address, - pool_name, - NULL AS fee, - NULL AS tick_spacing, - MAX( - CASE - WHEN token_num = 1 THEN token_address - END - ) AS token0, - MAX( - CASE - WHEN token_num = 2 THEN token_address - END - ) AS token1, - MAX( - CASE - WHEN token_num = 3 THEN token_address - END - ) AS token2, - MAX( - CASE - WHEN token_num = 4 THEN token_address - END - ) AS token3, - MAX( - CASE - WHEN token_num = 5 THEN token_address - END - ) AS token4, - MAX( - CASE - WHEN token_num = 6 THEN token_address - END - ) AS token5, - MAX( - CASE - WHEN token_num = 7 THEN token_address - END - ) AS token6, - MAX( - CASE - WHEN token_num = 8 THEN token_address - END - ) AS token7, - 'curve' AS platform, - 'v1' AS version, - _call_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__curve_pools') }} - -{% if is_incremental() and 'curve' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -GROUP BY - ALL -), -camelot AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'camelot' AS platform, - 'v1' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__camelot_pools') }} - -{% if is_incremental() and 'camelot' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -dodo_v1 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - base_token AS token0, - quote_token AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'dodo-v1' AS platform, - 'v1' AS version, - _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__dodo_v1_pools') }} - -{% if is_incremental() and 'dodo_v1' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -dodo_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - base_token AS token0, - quote_token AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'dodo-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__dodo_v2_pools') }} - WHERE - token0 IS NOT NULL - -{% if is_incremental() and 'dodo_v2' not in var('HEAL_MODELS') %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} -) -{% endif %} -), -frax AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - factory_address AS contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'fraxswap' AS platform, - 'v1' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__fraxswap_pools') }} - -{% if is_incremental() and 'frax' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -kyberswap_v1_dynamic AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'kyberswap-v1' AS platform, - 'v1-dynamic' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__kyberswap_v1_dynamic_pools') }} - -{% if is_incremental() and 'kyberswap_v1_dynamic' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -kyberswap_v1_static AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'kyberswap-v1' AS platform, - 'v1-static' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__kyberswap_v1_static_pools') }} - -{% if is_incremental() and 'kyberswap_v1_static' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -kyberswap_v2_elastic AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - swap_fee_units AS fee, - tick_distance AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'kyberswap-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__kyberswap_v2_elastic_pools') }} - -{% if is_incremental() and 'kyberswap_v2_elastic' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -sushi AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'sushiswap' AS platform, - 'v1' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__sushi_pools') }} - -{% if is_incremental() and 'sushi' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -sushi_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - fee, - tick_spacing, - token0_address AS token0, - token1_address AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'sushiswap-v3' AS platform, - 'v3' AS version, - _log_id AS _id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('silver_dex__sushi_pools_v3') }} - -{% if is_incremental() and 'sushi_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -trader_joe_v1 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'trader-joe-v1' AS platform, - 'v1' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__trader_joe_v1_pools') }} - -{% if is_incremental() and 'trader_joe_v1' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -trader_joe_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - lb_pair AS pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - tokenX AS token0, - tokenY AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'trader-joe-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__trader_joe_v2_pools') }} - -{% if is_incremental() and 'trader_joe_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -zyberswap AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'zyberswap' AS platform, - 'v1' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__zyberswap_pools') }} - -{% if is_incremental() and 'zyberswap' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -ramses_v2 AS ( - SELECT - created_block AS block_number, - created_time AS block_timestamp, - created_tx_hash AS tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - fee, - tick_spacing, - token0_address AS token0, - token1_address AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'ramses-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__ramses_v2_pools') }} - -{% if is_incremental() and 'ramses_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -uni_v3 AS ( - SELECT - created_block AS block_number, - created_time AS block_timestamp, - created_tx_hash AS tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - fee, - tick_spacing, - token0_address AS token0, - token1_address AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'uniswap-v3' AS platform, - 'v3' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__univ3_pools') }} - -{% if is_incremental() and 'uni_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -uni_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'uniswap-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__univ2_pools') }} - -{% if is_incremental() and 'uni_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -sparta AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - NULL AS tick_spacing, - token0, - token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'uniswap-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - _inserted_timestamp - FROM - {{ ref('silver_dex__sparta_pools') }} - -{% if is_incremental() and 'sparta' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -maverick_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - NULL AS fee, - -- passing null as maverick uses feeA and feeB - tick_spacing, - tokenA AS token0, - tokenB AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'maverick-v2' AS platform, - 'v2' AS version, - _log_id AS _id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('silver_dex__maverick_v2_pools') }} - -{% if is_incremental() and 'maverick_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -pancakeswap_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - NULL AS pool_name, - fee, - tick_spacing, - token0_address AS token0, - token1_address AS token1, - NULL AS token2, - NULL AS token3, - NULL AS token4, - NULL AS token5, - NULL AS token6, - NULL AS token7, - 'pancakeswap-v3' AS platform, - 'v3' AS version, - _log_id AS _id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('silver_dex__pancakeswap_v3_pools') }} - -{% if is_incremental() and 'pancakeswap_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -all_pools AS ( - SELECT - * - FROM - camelot - UNION ALL - SELECT - * - FROM - dodo_v1 - UNION ALL - SELECT - * - FROM - dodo_v2 - UNION ALL - SELECT - * - FROM - frax - UNION ALL - SELECT - * - FROM - kyberswap_v1_dynamic - UNION ALL - SELECT - * - FROM - kyberswap_v1_static - UNION ALL - SELECT - * - FROM - sushi - UNION ALL - SELECT - * - FROM - sushi_v3 - UNION ALL - SELECT - * - FROM - uni_v2 - UNION ALL - SELECT - * - FROM - sparta - UNION ALL - SELECT - * - FROM - trader_joe_v1 - UNION ALL - SELECT - * - FROM - trader_joe_v2 - UNION ALL - SELECT - * - FROM - zyberswap - UNION ALL - SELECT - * - FROM - uni_v3 - UNION ALL - SELECT - * - FROM - ramses_v2 - UNION ALL - SELECT - * - FROM - kyberswap_v2_elastic - UNION ALL - SELECT - * - FROM - balancer - UNION ALL - SELECT - * - FROM - curve - UNION ALL - SELECT - * - FROM - maverick_v2 - UNION ALL - SELECT - * - FROM - pancakeswap_v3 -), -complete_lps AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - p.contract_address, - pool_address, - CASE - WHEN pool_name IS NOT NULL THEN pool_name - WHEN pool_name IS NULL - AND platform IN ( - 'uniswap-v3', - 'kyberswap-v2', - 'ramses-v2', - 'pancakeswap-v3', - 'sushiswap-v3', - 'maverick-v2' - ) THEN CONCAT( - COALESCE( - c0.token_symbol, - CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42)) - ), - '-', - COALESCE( - c1.token_symbol, - CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42)) - ), - ' ', - COALESCE( - fee, - 0 - ), - ' ', - COALESCE( - tick_spacing, - 0 - ), - CASE - WHEN platform = 'uniswap-v3' THEN ' UNI-V3 LP' - WHEN platform = 'kyberswap-v2' THEN '' - WHEN platform = 'ramses-v2' THEN '' - WHEN platform = 'pancakeswap-v3' THEN 'PCS-V3 LP' - WHEN platform = 'sushiswap-v3' THEN 'SUSHI-V3 LP' - WHEN platform = 'maverick-v2' THEN 'MPv2 LP' - END - ) - WHEN pool_name IS NULL - AND platform IN ( - 'balancer', - 'curve' - ) THEN CONCAT( - COALESCE(c0.token_symbol, SUBSTRING(token0, 1, 5) || '...' || SUBSTRING(token0, 39, 42)), - CASE - WHEN token1 IS NOT NULL THEN '-' || COALESCE(c1.token_symbol, SUBSTRING(token1, 1, 5) || '...' || SUBSTRING(token1, 39, 42)) - ELSE '' - END, - CASE - WHEN token2 IS NOT NULL THEN '-' || COALESCE(c2.token_symbol, SUBSTRING(token2, 1, 5) || '...' || SUBSTRING(token2, 39, 42)) - ELSE '' - END, - CASE - WHEN token3 IS NOT NULL THEN '-' || COALESCE(c3.token_symbol, SUBSTRING(token3, 1, 5) || '...' || SUBSTRING(token3, 39, 42)) - ELSE '' - END, - CASE - WHEN token4 IS NOT NULL THEN '-' || COALESCE(c4.token_symbol, SUBSTRING(token4, 1, 5) || '...' || SUBSTRING(token4, 39, 42)) - ELSE '' - END, - CASE - WHEN token5 IS NOT NULL THEN '-' || COALESCE(c5.token_symbol, SUBSTRING(token5, 1, 5) || '...' || SUBSTRING(token5, 39, 42)) - ELSE '' - END, - CASE - WHEN token6 IS NOT NULL THEN '-' || COALESCE(c6.token_symbol, SUBSTRING(token6, 1, 5) || '...' || SUBSTRING(token6, 39, 42)) - ELSE '' - END, - CASE - WHEN token7 IS NOT NULL THEN '-' || COALESCE(c7.token_symbol, SUBSTRING(token7, 1, 5) || '...' || SUBSTRING(token7, 39, 42)) - ELSE '' - END - ) - ELSE CONCAT( - COALESCE( - c0.token_symbol, - CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42)) - ), - '-', - COALESCE( - c1.token_symbol, - CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42)) - ) - ) - END AS pool_name, - fee, - tick_spacing, - token0, - token1, - token2, - token3, - token4, - token5, - token6, - token7, - OBJECT_CONSTRUCT( - 'token0', - token0, - 'token1', - token1, - 'token2', - token2, - 'token3', - token3, - 'token4', - token4, - 'token5', - token5, - 'token6', - token6, - 'token7', - token7 - ) AS tokens, - OBJECT_CONSTRUCT( - 'token0', - c0.token_symbol, - 'token1', - c1.token_symbol, - 'token2', - c2.token_symbol, - 'token3', - c3.token_symbol, - 'token4', - c4.token_symbol, - 'token5', - c5.token_symbol, - 'token6', - c6.token_symbol, - 'token7', - c7.token_symbol - ) AS symbols, - OBJECT_CONSTRUCT( - 'token0', - c0.token_decimals, - 'token1', - c1.token_decimals, - 'token2', - c2.token_decimals, - 'token3', - c3.token_decimals, - 'token4', - c4.token_decimals, - 'token5', - c5.token_decimals, - 'token6', - c6.token_decimals, - 'token7', - c7.token_decimals - ) AS decimals, - platform, - version, - _id, - p._inserted_timestamp - FROM - all_pools p - LEFT JOIN contracts c0 - ON c0.contract_address = p.token0 - LEFT JOIN contracts c1 - ON c1.contract_address = p.token1 - LEFT JOIN contracts c2 - ON c2.contract_address = p.token2 - LEFT JOIN contracts c3 - ON c3.contract_address = p.token3 - LEFT JOIN contracts c4 - ON c4.contract_address = p.token4 - LEFT JOIN contracts c5 - ON c5.contract_address = p.token5 - LEFT JOIN contracts c6 - ON c6.contract_address = p.token6 - LEFT JOIN contracts c7 - ON c7.contract_address = p.token7 -), - -{% if is_incremental() and var( - 'HEAL_MODEL' -) %} -heal_model AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - t0.contract_address, - pool_address, - CASE - WHEN pool_name IS NOT NULL THEN pool_name - WHEN pool_name IS NULL - AND platform IN ( - 'uniswap-v3', - 'kyberswap-v2', - 'ramses-v2', - 'pancakeswap-v3', - 'sushiswap-v3', - 'maverick-v2' - ) THEN CONCAT( - COALESCE( - c0.token_symbol, - CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42)) - ), - '-', - COALESCE( - c1.token_symbol, - CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42)) - ), - ' ', - COALESCE( - fee, - 0 - ), - ' ', - COALESCE( - tick_spacing, - 0 - ), - CASE - WHEN platform = 'uniswap-v3' THEN ' UNI-V3 LP' - WHEN platform = 'kyberswap-v2' THEN '' - WHEN platform = 'ramses-v2' THEN '' - WHEN platform = 'pancakeswap-v3' THEN 'PCS-V3 LP' - WHEN platform = 'sushiswap-v3' THEN 'SUSHI-V3 LP' - WHEN platform = 'maverick-v2' THEN 'MPv2 LP' - END - ) - WHEN pool_name IS NULL - AND platform IN ( - 'balancer', - 'curve' - ) THEN CONCAT( - COALESCE(c0.token_symbol, SUBSTRING(token0, 1, 5) || '...' || SUBSTRING(token0, 39, 42)), - CASE - WHEN token1 IS NOT NULL THEN '-' || COALESCE(c1.token_symbol, SUBSTRING(token1, 1, 5) || '...' || SUBSTRING(token1, 39, 42)) - ELSE '' - END, - CASE - WHEN token2 IS NOT NULL THEN '-' || COALESCE(c2.token_symbol, SUBSTRING(token2, 1, 5) || '...' || SUBSTRING(token2, 39, 42)) - ELSE '' - END, - CASE - WHEN token3 IS NOT NULL THEN '-' || COALESCE(c3.token_symbol, SUBSTRING(token3, 1, 5) || '...' || SUBSTRING(token3, 39, 42)) - ELSE '' - END, - CASE - WHEN token4 IS NOT NULL THEN '-' || COALESCE(c4.token_symbol, SUBSTRING(token4, 1, 5) || '...' || SUBSTRING(token4, 39, 42)) - ELSE '' - END, - CASE - WHEN token5 IS NOT NULL THEN '-' || COALESCE(c5.token_symbol, SUBSTRING(token5, 1, 5) || '...' || SUBSTRING(token5, 39, 42)) - ELSE '' - END, - CASE - WHEN token6 IS NOT NULL THEN '-' || COALESCE(c6.token_symbol, SUBSTRING(token6, 1, 5) || '...' || SUBSTRING(token6, 39, 42)) - ELSE '' - END, - CASE - WHEN token7 IS NOT NULL THEN '-' || COALESCE(c7.token_symbol, SUBSTRING(token7, 1, 5) || '...' || SUBSTRING(token7, 39, 42)) - ELSE '' - END - ) - ELSE CONCAT( - COALESCE( - c0.token_symbol, - CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42)) - ), - '-', - COALESCE( - c1.token_symbol, - CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42)) - ) - ) - END AS pool_name_heal, - fee, - tick_spacing, - token0, - token1, - token2, - token3, - token4, - token5, - token6, - token7, - tokens, - OBJECT_CONSTRUCT( - 'token0', - c0.token_symbol, - 'token1', - c1.token_symbol, - 'token2', - c2.token_symbol, - 'token3', - c3.token_symbol, - 'token4', - c4.token_symbol, - 'token5', - c5.token_symbol, - 'token6', - c6.token_symbol, - 'token7', - c7.token_symbol - ) AS symbols_heal, - OBJECT_CONSTRUCT( - 'token0', - c0.token_decimals, - 'token1', - c1.token_decimals, - 'token2', - c2.token_decimals, - 'token3', - c3.token_decimals, - 'token4', - c4.token_decimals, - 'token5', - c5.token_decimals, - 'token6', - c6.token_decimals, - 'token7', - c7.token_decimals - ) AS decimals_heal, - platform, - version, - _id, - t0._inserted_timestamp - FROM - {{ this }} - t0 - LEFT JOIN contracts c0 - ON c0.contract_address = t0.token0 - LEFT JOIN contracts c1 - ON c1.contract_address = t0.token1 - LEFT JOIN contracts c2 - ON c2.contract_address = t0.token2 - LEFT JOIN contracts c3 - ON c3.contract_address = t0.token3 - LEFT JOIN contracts c4 - ON c4.contract_address = t0.token4 - LEFT JOIN contracts c5 - ON c5.contract_address = t0.token5 - LEFT JOIN contracts c6 - ON c6.contract_address = t0.token6 - LEFT JOIN contracts c7 - ON c7.contract_address = t0.token7 - WHERE - CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t1.block_number, - '-', - t1.platform, - '-', - t1.version - ) - FROM - {{ this }} - t1 - WHERE - t1.decimals :token0 :: INT IS NULL - AND t1._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t1.tokens :token0 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t2.block_number, - '-', - t2.platform, - '-', - t2.version - ) - FROM - {{ this }} - t2 - WHERE - t2.decimals :token1 :: INT IS NULL - AND t2._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t2.tokens :token1 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t3.block_number, - '-', - t3.platform, - '-', - t3.version - ) - FROM - {{ this }} - t3 - WHERE - t3.decimals :token2 :: INT IS NULL - AND t3._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t3.tokens :token2 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t4.block_number, - '-', - t4.platform, - '-', - t4.version - ) - FROM - {{ this }} - t4 - WHERE - t4.decimals :token3 :: INT IS NULL - AND t4._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t4.tokens :token3 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t5.block_number, - '-', - t5.platform, - '-', - t5.version - ) - FROM - {{ this }} - t5 - WHERE - t5.decimals :token4 :: INT IS NULL - AND t5._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t5.tokens :token4 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t6.block_number, - '-', - t6.platform, - '-', - t6.version - ) - FROM - {{ this }} - t6 - WHERE - t6.decimals :token5 :: INT IS NULL - AND t6._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t6.tokens :token5 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t7.block_number, - '-', - t7.platform, - '-', - t7.version - ) - FROM - {{ this }} - t7 - WHERE - t7.decimals :token6 :: INT IS NULL - AND t7._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t7.tokens :token6 :: STRING) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t8.block_number, - '-', - t8.platform, - '-', - t8.version - ) - FROM - {{ this }} - t8 - WHERE - t8.decimals :token7 :: INT IS NULL - AND t8._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t8.tokens :token7 :: STRING) - GROUP BY - 1 - ) - ), - {% endif %} - - FINAL AS ( - SELECT - * - FROM - complete_lps - -{% if is_incremental() and var( - 'HEAL_MODEL' -) %} -UNION ALL -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - pool_address, - pool_name_heal AS pool_name, - fee, - tick_spacing, - token0, - token1, - token2, - token3, - token4, - token5, - token6, - token7, - tokens, - symbols_heal AS symbols, - decimals_heal AS decimals, - platform, - version, - _id, - _inserted_timestamp -FROM - heal_model -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - platform, - version, - contract_address, - pool_address, - pool_name, - tokens, - symbols, - decimals, - fee, - tick_spacing, - token0, - token1, - token2, - token3, - token4, - token5, - token6, - token7, - _id, - _inserted_timestamp, - {{ dbt_utils.generate_surrogate_key( - ['pool_address'] - ) }} AS complete_dex_liquidity_pools_id, - SYSDATE() AS inserted_timestamp, - SYSDATE() AS modified_timestamp, - '{{ invocation_id }}' AS _invocation_id -FROM - FINAL diff --git a/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.yml b/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.yml deleted file mode 100644 index e996dc6..0000000 --- a/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.yml +++ /dev/null @@ -1,44 +0,0 @@ -version: 2 -models: - - name: silver_dex__complete_dex_liquidity_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: POOL_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: _ID - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql b/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql deleted file mode 100644 index 3b429dc..0000000 --- a/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql +++ /dev/null @@ -1,1715 +0,0 @@ --- depends_on: {{ ref('silver__complete_token_prices') }} --- depends_on: {{ ref('price__ez_asset_metadata') }} -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = ['block_number','platform','version'], - cluster_by = ['block_timestamp::DATE','platform'], - post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_function_signature, origin_from_address, origin_to_address, contract_address, pool_name, event_name, sender, tx_to, token_in, token_out, symbol_in, symbol_out), SUBSTRING(origin_function_signature, pool_name, event_name, sender, tx_to, token_in, token_out, symbol_in, symbol_out)", - tags = ['silver_dex','defi','dex','curated','heal'] -) }} - -WITH ramses_v2 AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - pool_address AS contract_address, - 'Swap' AS event_name, - CASE - WHEN amount0_unadj > 0 THEN ABS(amount0_unadj) - ELSE ABS(amount1_unadj) - END AS amount_in_unadj, - CASE - WHEN amount0_unadj < 0 THEN ABS(amount0_unadj) - ELSE ABS(amount1_unadj) - END AS amount_out_unadj, - CASE - WHEN amount0_unadj > 0 THEN token0_address - ELSE token1_address - END AS token_in, - CASE - WHEN amount0_unadj < 0 THEN token0_address - ELSE token1_address - END AS token_out, - sender, - recipient AS tx_to, - event_index, - 'ramses-v2' AS platform, - 'ramses' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__ramses_v2_swaps') }} - -{% if is_incremental() and 'ramses_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -univ3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - pool_address AS contract_address, - 'Swap' AS event_name, - CASE - WHEN amount0_unadj > 0 THEN ABS(amount0_unadj) - ELSE ABS(amount1_unadj) - END AS amount_in_unadj, - CASE - WHEN amount0_unadj < 0 THEN ABS(amount0_unadj) - ELSE ABS(amount1_unadj) - END AS amount_out_unadj, - CASE - WHEN amount0_unadj > 0 THEN token0_address - ELSE token1_address - END AS token_in, - CASE - WHEN amount0_unadj < 0 THEN token0_address - ELSE token1_address - END AS token_out, - sender, - recipient AS tx_to, - event_index, - 'uniswap-v3' AS platform, - 'uniswap' AS protocol, - 'v3' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__univ3_swaps') }} - -{% if is_incremental() and 'univ3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -balancer AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'balancer' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__balancer_swaps') }} - -{% if is_incremental() and 'balancer' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -curve AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - tokens_sold AS amount_in_unadj, - tokens_bought AS amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'curve' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__curve_swaps') }} - -{% if is_incremental() and 'curve' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -trader_joe_v1 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'trader_joe' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__trader_joe_v1_swaps') }} - -{% if is_incremental() and 'trader_joe_v1' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -trader_joe_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'trader_joe' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__trader_joe_v2_swaps') }} - -{% if is_incremental() and 'trader_joe_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -trader_joe_v2_1 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'trader_joe' AS protocol, - version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__trader_joe_v2_1_swaps') }} - -{% if is_incremental() and 'trader_joe_v2_1' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -woofi AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'woofi' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__woofi_swaps') }} - -{% if is_incremental() and 'woofi' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -hashflow AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'hashflow' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__hashflow_swaps') }} - -{% if is_incremental() and 'hashflow' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -hashflow_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'hashflow' AS protocol, - 'v3' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__hashflow_v3_swaps') }} - -{% if is_incremental() and 'hashflow_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -gmx AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'gmx' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__gmx_swaps') }} - -{% if is_incremental() and 'gmx' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -gmx_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'gmx' AS protocol, - 'v2' AS version, - _log_id, - modified_timestamp as _inserted_timestamp - FROM - {{ ref('silver_dex__gmx_v2_swaps') }} - -{% if is_incremental() and 'gmx_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -kyberswap_v1_dynamic AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'kyberswap' AS protocol, - 'v1-dynamic' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__kyberswap_v1_dynamic_swaps') }} - -{% if is_incremental() and 'kyberswap_v1_dynamic' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -kyberswap_v1_static AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'kyberswap' AS protocol, - 'v1-static' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__kyberswap_v1_static_swaps') }} - -{% if is_incremental() and 'kyberswap_v1_static' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -kyberswap_v2_elastic AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'kyberswap' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__kyberswap_v2_elastic_swaps') }} - -{% if is_incremental() and 'kyberswap_v2_elastic' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -fraxswap AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'fraxswap' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__fraxswap_swaps') }} - -{% if is_incremental() and 'fraxswap' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -pancakeswap_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'pancakeswap' AS protocol, - 'v3' AS version, - _log_id, - modified_timestamp as _inserted_timestamp - FROM - {{ ref('silver_dex__pancakeswap_v3_swaps') }} - -{% if is_incremental() and 'pancakeswap_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -sushi AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'sushiswap' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__sushi_swaps') }} - -{% if is_incremental() and 'sushi' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -sushi_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - 'Swap' as event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - 'sushiswap-v3' as platform, - 'sushiswap' AS protocol, - 'v3' AS version, - _log_id, - modified_timestamp as _inserted_timestamp - FROM - {{ ref('silver_dex__sushi_swaps_v3') }} - -{% if is_incremental() and 'sushi_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -univ2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'uniswap' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__univ2_swaps') }} - -{% if is_incremental() and 'univ2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -sparta AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'sparta' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__sparta_swaps') }} - -{% if is_incremental() and 'sparta' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -dexalot AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'dexalot' AS protocol, - 'v1' AS version, - _log_id, - modified_timestamp as _inserted_timestamp - FROM - {{ ref('silver_dex__dexalot_swaps') }} - -{% if is_incremental() and 'dexalot' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -dodo_v1 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'dodo' AS protocol, - 'v1' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__dodo_v1_swaps') }} - -{% if is_incremental() and 'dodo_v1' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -dodo_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'dodo' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__dodo_v2_swaps') }} - -{% if is_incremental() and 'dodo_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -camelot_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'camelot' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__camelot_v2_swaps') }} - -{% if is_incremental() and 'camelot_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -camelot_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'camelot' AS protocol, - 'v3' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__camelot_v3_swaps') }} - -{% if is_incremental() and 'camelot_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -maverick_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'maverick' AS protocol, - 'v2' AS version, - _log_id, - modified_timestamp as _inserted_timestamp - FROM - {{ ref('silver_dex__maverick_v2_swaps') }} - -{% if is_incremental() and 'maverick_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -zyberswap_v2 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'zyberswap' AS protocol, - 'v2' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__zyberswap_v2_swaps') }} - -{% if is_incremental() and 'zyberswap_v2' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -zyberswap_v3 AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - amount_in_unadj, - amount_out_unadj, - token_in, - token_out, - sender, - tx_to, - event_index, - platform, - 'zyberswap' AS protocol, - 'v3' AS version, - _log_id, - _inserted_timestamp - FROM - {{ ref('silver_dex__zyberswap_v3_swaps') }} - -{% if is_incremental() and 'zyberswap_v3' not in var('HEAL_MODELS') %} -WHERE - _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) -{% endif %} -), -all_dex AS ( - SELECT - * - FROM - balancer - UNION ALL - SELECT - * - FROM - camelot_v2 - UNION ALL - SELECT - * - FROM - camelot_v3 - UNION ALL - SELECT - * - FROM - curve - UNION ALL - SELECT - * - FROM - hashflow - UNION ALL - SELECT - * - FROM - hashflow_v3 - UNION ALL - SELECT - * - FROM - dodo_v1 - UNION ALL - SELECT - * - FROM - dodo_v2 - UNION ALL - SELECT - * - FROM - fraxswap - UNION ALL - SELECT - * - FROM - gmx - UNION ALL - SELECT - * - FROM - gmx_v2 - UNION ALL - SELECT - * - FROM - kyberswap_v1_dynamic - UNION ALL - SELECT - * - FROM - kyberswap_v1_static - UNION ALL - SELECT - * - FROM - kyberswap_v2_elastic - UNION ALL - SELECT - * - FROM - dexalot - UNION ALL - SELECT - * - FROM - maverick_v2 - UNION ALL - SELECT - * - FROM - pancakeswap_v3 - UNION ALL - SELECT - * - FROM - sushi - UNION ALL - SELECT - * - FROM - sushi_v3 - UNION ALL - SELECT - * - FROM - univ2 - UNION ALL - SELECT - * - FROM - sparta - UNION ALL - SELECT - * - FROM - trader_joe_v1 - UNION ALL - SELECT - * - FROM - trader_joe_v2_1 - UNION ALL - SELECT - * - FROM - trader_joe_v2 - UNION ALL - SELECT - * - FROM - woofi - UNION ALL - SELECT - * - FROM - zyberswap_v2 - UNION ALL - SELECT - * - FROM - zyberswap_v3 - UNION ALL - SELECT - * - FROM - univ3 - UNION ALL - SELECT - * - FROM - ramses_v2 -), -complete_dex_swaps AS ( - SELECT - s.block_number, - s.block_timestamp, - s.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - s.contract_address, - event_name, - token_in, - p1.is_verified as token_in_is_verified, - c1.token_decimals AS decimals_in, - c1.token_symbol AS symbol_in, - amount_in_unadj, - CASE - WHEN decimals_in IS NULL THEN amount_in_unadj - ELSE (amount_in_unadj / pow(10, decimals_in)) - END AS amount_in, - CASE - WHEN decimals_in IS NOT NULL THEN amount_in * p1.price - ELSE NULL - END AS amount_in_usd, - token_out, - p2.is_verified as token_out_is_verified, - c2.token_decimals AS decimals_out, - c2.token_symbol AS symbol_out, - amount_out_unadj, - CASE - WHEN decimals_out IS NULL THEN amount_out_unadj - ELSE (amount_out_unadj / pow(10, decimals_out)) - END AS amount_out, - CASE - WHEN decimals_out IS NOT NULL THEN amount_out * p2.price - ELSE NULL - END AS amount_out_usd, - CASE - WHEN lp.pool_name IS NULL THEN CONCAT( - LEAST( - COALESCE( - symbol_in, - CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42)) - ), - COALESCE( - symbol_out, - CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)) - ) - ), - '-', - GREATEST( - COALESCE( - symbol_in, - CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42)) - ), - COALESCE( - symbol_out, - CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)) - ) - ) - ) - ELSE lp.pool_name - END AS pool_name, - sender, - tx_to, - event_index, - s.platform, - s.protocol, - s.version, - s._log_id, - s._inserted_timestamp - FROM - all_dex s - LEFT JOIN {{ ref('silver__contracts') }} - c1 - ON s.token_in = c1.contract_address - LEFT JOIN {{ ref('silver__contracts') }} - c2 - ON s.token_out = c2.contract_address - LEFT JOIN {{ ref('price__ez_prices_hourly') }} - p1 - ON s.token_in = p1.token_address - AND DATE_TRUNC( - 'hour', - block_timestamp - ) = p1.hour - LEFT JOIN {{ ref('price__ez_prices_hourly') }} - p2 - ON s.token_out = p2.token_address - AND DATE_TRUNC( - 'hour', - block_timestamp - ) = p2.hour - LEFT JOIN {{ ref('silver_dex__complete_dex_liquidity_pools') }} - lp - ON s.contract_address = lp.pool_address -), - -{% if is_incremental() and var( - 'HEAL_MODEL' -) %} -heal_model AS ( - SELECT - t0.block_number, - t0.block_timestamp, - t0.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - t0.contract_address, - event_name, - token_in, - p1.is_verified as token_in_is_verified, - c1.token_decimals AS decimals_in, - c1.token_symbol AS symbol_in, - amount_in_unadj, - CASE - WHEN c1.token_decimals IS NULL THEN amount_in_unadj - ELSE (amount_in_unadj / pow(10, c1.token_decimals)) - END AS amount_in_heal, - CASE - WHEN c1.token_decimals IS NOT NULL THEN amount_in_heal * p1.price - ELSE NULL - END AS amount_in_usd_heal, - token_out, - p2.is_verified as token_out_is_verified, - c2.token_decimals AS decimals_out, - c2.token_symbol AS symbol_out, - amount_out_unadj, - CASE - WHEN c2.token_decimals IS NULL THEN amount_out_unadj - ELSE (amount_out_unadj / pow(10, c2.token_decimals)) - END AS amount_out_heal, - CASE - WHEN c2.token_decimals IS NOT NULL THEN amount_out_heal * p2.price - ELSE NULL - END AS amount_out_usd_heal, - CASE - WHEN lp.pool_name IS NULL THEN CONCAT( - LEAST( - COALESCE( - c1.token_symbol, - CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42)) - ), - COALESCE( - c2.token_symbol, - CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)) - ) - ), - '-', - GREATEST( - COALESCE( - c1.token_symbol, - CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42)) - ), - COALESCE( - c2.token_symbol, - CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)) - ) - ) - ) - ELSE lp.pool_name - END AS pool_name_heal, - sender, - tx_to, - event_index, - t0.platform, - t0.protocol, - t0.version, - t0._log_id, - t0._inserted_timestamp - FROM - {{ this }} - t0 - LEFT JOIN {{ ref('silver__contracts') }} - c1 - ON t0.token_in = c1.contract_address - LEFT JOIN {{ ref('silver__contracts') }} - c2 - ON t0.token_out = c2.contract_address - LEFT JOIN {{ ref('price__ez_prices_hourly') }} - p1 - ON t0.token_in = p1.token_address - AND DATE_TRUNC( - 'hour', - block_timestamp - ) = p1.hour - LEFT JOIN {{ ref('price__ez_prices_hourly') }} - p2 - ON t0.token_out = p2.token_address - AND DATE_TRUNC( - 'hour', - block_timestamp - ) = p2.hour - LEFT JOIN {{ ref('silver_dex__complete_dex_liquidity_pools') }} - lp - ON t0.contract_address = lp.pool_address - WHERE - CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t1.block_number, - '-', - t1.platform, - '-', - t1.version - ) - FROM - {{ this }} - t1 - WHERE - t1.decimals_in IS NULL - AND t1._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t1.token_in) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t2.block_number, - '-', - t2.platform, - '-', - t2.version - ) - FROM - {{ this }} - t2 - WHERE - t2.decimals_out IS NULL - AND t2._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__contracts') }} C - WHERE - C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND C.token_decimals IS NOT NULL - AND C.contract_address = t2.token_out) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t3.block_number, - '-', - t3.platform, - '-', - t3.version - ) - FROM - {{ this }} - t3 - WHERE - t3.amount_in_usd IS NULL - AND t3._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__complete_token_prices') }} - p - WHERE - p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND p.price IS NOT NULL - AND p.token_address = t3.token_in - AND p.hour = DATE_TRUNC( - 'hour', - t3.block_timestamp - ) - ) - GROUP BY - 1 - ) - OR CONCAT( - t0.block_number, - '-', - t0.platform, - '-', - t0.version - ) IN ( - SELECT - CONCAT( - t4.block_number, - '-', - t4.platform, - '-', - t4.version - ) - FROM - {{ this }} - t4 - WHERE - t4.amount_out_usd IS NULL - AND t4._inserted_timestamp < ( - SELECT - MAX( - _inserted_timestamp - ) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}' - FROM - {{ this }} - ) - AND EXISTS ( - SELECT - 1 - FROM - {{ ref('silver__complete_token_prices') }} - p - WHERE - p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE()) - AND p.price IS NOT NULL - AND p.token_address = t4.token_out - AND p.hour = DATE_TRUNC( - 'hour', - t4.block_timestamp - ) - ) - GROUP BY - 1 - ) - ), newly_verified_tokens as ( - select token_address - from {{ ref('price__ez_asset_metadata') }} - where ifnull(is_verified_modified_timestamp, '1970-01-01' :: TIMESTAMP) > dateadd('day', -10, SYSDATE()) - ), - heal_newly_verified_tokens as ( - select - t0.block_number, - t0.block_timestamp, - t0.tx_hash, - t0.origin_function_signature, - t0.origin_from_address, - t0.origin_to_address, - t0.contract_address, - t0.event_name, - t0.token_in, - p1.is_verified AS token_in_is_verified, - t0.decimals_in, - t0.symbol_in, - t0.amount_in_unadj, - t0.amount_in, - CASE - WHEN decimals_in IS NOT NULL THEN amount_in * p1.price - ELSE NULL - END AS amount_in_usd_heal, - token_out, - p2.is_verified AS token_out_is_verified, - t0.decimals_out, - t0.symbol_out, - t0.amount_out_unadj, - t0.amount_out, - CASE - WHEN decimals_out IS NOT NULL THEN amount_out * p2.price - ELSE NULL - END AS amount_out_usd_heal, - t0.pool_name, - t0.sender, - t0.tx_to, - t0.event_index, - t0.platform, - t0.protocol, - t0.version, - t0._log_id, - t0._inserted_timestamp - from {{ this }} t0 - join newly_verified_tokens nv - on (t0.token_in = nv.token_address or t0.token_out = nv.token_address) - left join {{ ref('price__ez_prices_hourly')}} p1 - on t0.token_in = p1.token_address - and date_trunc('hour', t0.block_timestamp) = p1.hour - left join {{ ref('price__ez_prices_hourly')}} p2 - on t0.token_out = p2.token_address - and date_trunc('hour', t0.block_timestamp) = p2.hour - ), - {% endif %} - - FINAL AS ( - SELECT - * - FROM - complete_dex_swaps - -{% if is_incremental() and var( - 'HEAL_MODEL' -) %} -UNION ALL -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - token_in, - token_in_is_verified, - decimals_in, - symbol_in, - amount_in_unadj, - amount_in_heal AS amount_in, - amount_in_usd_heal AS amount_in_usd, - token_out, - token_out_is_verified, - decimals_out, - symbol_out, - amount_out_unadj, - amount_out_heal AS amount_out, - amount_out_usd_heal AS amount_out_usd, - pool_name_heal AS pool_name, - sender, - tx_to, - event_index, - platform, - protocol, - version, - _log_id, - _inserted_timestamp -FROM - heal_model -UNION ALL -SELECT - * -FROM - heal_newly_verified_tokens -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - pool_name, - event_name, - amount_in_unadj, - amount_in, - amount_in_usd, - amount_out_unadj, - amount_out, - amount_out_usd, - sender, - tx_to, - event_index, - platform, - protocol, - version, - token_in, - IFNULL(token_in_is_verified, FALSE) AS token_in_is_verified, - token_out, - IFNULL(token_out_is_verified, FALSE) AS token_out_is_verified, - symbol_in, - symbol_out, - decimals_in, - decimals_out, - _log_id, - _inserted_timestamp, - {{ dbt_utils.generate_surrogate_key( - ['tx_hash','event_index'] - ) }} AS complete_dex_swaps_id, - SYSDATE() AS inserted_timestamp, - SYSDATE() AS modified_timestamp, - '{{ invocation_id }}' AS _invocation_id -FROM - FINAL qualify (ROW_NUMBER() over (PARTITION BY _log_id -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/silver_dex__complete_dex_swaps.yml b/models/silver/defi/dex/silver_dex__complete_dex_swaps.yml deleted file mode 100644 index 4b7351b..0000000 --- a/models/silver/defi/dex/silver_dex__complete_dex_swaps.yml +++ /dev/null @@ -1,130 +0,0 @@ -version: 2 -models: - - name: silver_dex__complete_dex_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: EVENT_NAME - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - not_null - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN_USD - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_USD - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null: - where: PLATFORM NOT IN ('uniswap-v3','curve') - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null: - where: PLATFORM NOT IN ('uniswap-v3','curve') - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - enabled: False - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/sparta/silver_dex__sparta_pools.sql b/models/silver/defi/dex/sparta/silver_dex__sparta_pools.sql deleted file mode 100644 index 2574231..0000000 --- a/models/silver/defi/dex/sparta/silver_dex__sparta_pools.sql +++ /dev/null @@ -1,62 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INT AS pool_id, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0xFe8EC10Fe07A6a6f4A2584f8cD9FE232930eAF55') - AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - pool_id, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/sparta/silver_dex__sparta_pools.yml b/models/silver/defi/dex/sparta/silver_dex__sparta_pools.yml deleted file mode 100644 index d0d5559..0000000 --- a/models/silver/defi/dex/sparta/silver_dex__sparta_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__sparta_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.sql b/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.sql deleted file mode 100644 index 90ac846..0000000 --- a/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.sql +++ /dev/null @@ -1,124 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__sparta_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) :: INTEGER - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INTEGER - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) :: INTEGER - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) :: INTEGER - ) AS amount1Out, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender, - tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'sparta' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.yml b/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.yml deleted file mode 100644 index 12679f2..0000000 --- a/models/silver/defi/dex/sparta/silver_dex__sparta_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__sparta_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql deleted file mode 100644 index 355d743..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.sql +++ /dev/null @@ -1,62 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INT AS pool_id, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0xc35DADB65012eC5796536bD9864eD8773aBc74C4') - AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - pool_id, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.yml b/models/silver/defi/dex/sushi/silver_dex__sushi_pools.yml deleted file mode 100644 index ba36a8b..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__sushi_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_pools_v3.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_pools_v3.sql deleted file mode 100644 index 42ef629..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_pools_v3.sql +++ /dev/null @@ -1,128 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH created_pools AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - LOWER(CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))) AS token0_address, - LOWER(CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))) AS token1_address, - utils.udf_hex_to_int( - 's2c', - topics [3] :: STRING - ) :: INTEGER AS fee, - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) :: INTEGER AS tick_spacing, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topic_0 = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' - AND contract_address = '0x1af415a1eba07a4986a52b6f2e7de7003d82231e' --Sushi/UniswapV3Factory - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -initial_info AS ( - SELECT - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS init_sqrtPriceX96, - utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [1] :: STRING)) :: FLOAT AS init_tick, - pow( - 1.0001, - init_tick - ) AS init_price_1_0_unadj, - CONCAT( - tx_hash, - '-', - event_index - ) AS _log_id, - modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topic_0 = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -FINAL AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - p.contract_address, - token0_address, - token1_address, - fee :: INTEGER AS fee, - ( - fee / 10000 - ) :: FLOAT AS fee_percent, - tick_spacing, - pool_address, - COALESCE( - init_tick, - 0 - ) AS init_tick, - p._log_id, - p.modified_timestamp - FROM - created_pools p - LEFT JOIN initial_info i - ON p.pool_address = i.contract_address -) -SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - token0_address, - token1_address, - fee, - fee_percent, - tick_spacing, - pool_address, - init_tick, - _log_id, - modified_timestamp -FROM - FINAL qualify(ROW_NUMBER() over(PARTITION BY pool_address -ORDER BY - modified_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_pools_v3.yml b/models/silver/defi/dex/sushi/silver_dex__sushi_pools_v3.yml deleted file mode 100644 index e315cbc..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_pools_v3.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__sushi_pools_v3 - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0_ADDRESS - tests: - - not_null - - name: TOKEN1_ADDRESS - tests: - - not_null - - - diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql deleted file mode 100644 index 7e7449b..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.sql +++ /dev/null @@ -1,124 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__sushi_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) :: INTEGER - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INTEGER - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) :: INTEGER - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) :: INTEGER - ) AS amount1Out, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender, - tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'sushiswap' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.yml b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.yml deleted file mode 100644 index 4032b0c..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__sushi_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 #might be normal for swaps not to happen on a day - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps_v3.sql b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps_v3.sql deleted file mode 100644 index 9b77364..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps_v3.sql +++ /dev/null @@ -1,117 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH swaps_base AS ( - - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - l.event_index, - l.origin_function_signature, - l.origin_from_address, - l.origin_to_address, - l.contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topic_1, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topic_2, 27, 40)) AS recipient, - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) :: FLOAT AS amount0_unadj, - utils.udf_hex_to_int( - 's2c', - segmented_data [1] :: STRING - ) :: FLOAT AS amount1_unadj, - utils.udf_hex_to_int( - 's2c', - segmented_data [2] :: STRING - ) :: FLOAT AS sqrtPriceX96, - utils.udf_hex_to_int( - 's2c', - segmented_data [3] :: STRING - ) :: FLOAT AS liquidity, - utils.udf_hex_to_int( - 's2c', - segmented_data [4] :: STRING - ) :: FLOAT AS tick, - token0_address, - token1_address, - pool_address, - tick_spacing, - fee, - CONCAT( - l.tx_hash, - '-', - l.event_index - ) AS _log_id, - l.modified_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN {{ ref('silver_dex__sushi_pools_v3') }} - p - ON p.pool_address = l.contract_address - WHERE - l.block_timestamp :: DATE >= '2023-04-01' - AND topic_0 = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_succeeded - -{% if is_incremental() %} -AND l.modified_timestamp >= ( - SELECT - MAX(modified_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - pool_address, - recipient, - recipient AS tx_to, - sender, - fee, - tick, - tick_spacing, - liquidity, - token0_address, - token1_address, - amount0_unadj, - amount1_unadj, - CASE - WHEN amount0_unadj > 0 THEN ABS(amount0_unadj) - ELSE ABS(amount1_unadj) - END AS amount_in_unadj, - CASE - WHEN amount0_unadj < 0 THEN ABS(amount0_unadj) - ELSE ABS(amount1_unadj) - END AS amount_out_unadj, - CASE - WHEN amount0_unadj > 0 THEN token0_address - ELSE token1_address - END AS token_in, - CASE - WHEN amount0_unadj < 0 THEN token0_address - ELSE token1_address - END AS token_out, - _log_id, - modified_timestamp -FROM - swaps_base qualify(ROW_NUMBER() over(PARTITION BY _log_id -ORDER BY - modified_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps_v3.yml b/models/silver/defi/dex/sushi/silver_dex__sushi_swaps_v3.yml deleted file mode 100644 index 048eb26..0000000 --- a/models/silver/defi/dex/sushi/silver_dex__sushi_swaps_v3.yml +++ /dev/null @@ -1,46 +0,0 @@ -version: 2 -models: - - name: silver_dex__sushi_swaps_v3 - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: POOL_ADDRESS - tests: - - not_null - - name: RECIPIENT - tests: - - not_null - - name: SENDER - tests: - - not_null - - name: TOKEN0_ADDRESS - tests: - - not_null - - name: TOKEN1_ADDRESS - tests: - - not_null - - name: AMOUNT0_UNADJ - tests: - - not_null - - name: AMOUNT1_UNADJ - tests: - - not_null diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.sql deleted file mode 100644 index 928ec05..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.sql +++ /dev/null @@ -1,62 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INT AS pool_id, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0xae4ec9901c3076d0ddbe76a520f9e90a6227acb7') - AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - pool_id, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.yml b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.yml deleted file mode 100644 index b27f9fc..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__trader_joe_v1_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.sql deleted file mode 100644 index 04c7410..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.sql +++ /dev/null @@ -1,125 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__trader_joe_v1_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS amount1Out, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = l.contract_address - WHERE - l.topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' --Swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - sender_address AS sender, - to_address AS tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'trader-joe-v1' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.yml b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.yml deleted file mode 100644 index aa60254..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v1_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__trader_joe_v1_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql deleted file mode 100644 index 33935cd..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.sql +++ /dev/null @@ -1,154 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - lb_pair, - tokenX, - tokenY, - version - FROM - {{ ref('silver_dex__trader_joe_v2_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.origin_function_signature, - l.origin_from_address, - l.origin_to_address, - l.tx_hash, - l.event_index, - l.contract_address, - l.topics, - l.data, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS id, - l_segmented_data [1] :: STRING AS amountsIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(amountsIn, 0, 32)) - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(amountsIn, 33, 32)) - ) AS amount1In, - l_segmented_data [2] :: STRING AS amountsOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(amountsOut, 0, 32)) - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(amountsOut, 33, 32)) - ) AS amount1Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS volatilityAccumulated, - l_segmented_data [4] :: STRING AS totalFees, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(totalFees, 0, 32)) - ) AS fee0, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(totalFees, 33, 32)) - ) AS fee1, - l_segmented_data [5] :: STRING AS protocolFees, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(protocolFees, 0, 32)) - ) AS protocolFee0, - TRY_TO_NUMBER( - utils.udf_hex_to_int(SUBSTR(protocolFees, 33, 32)) - ) AS protocolFee1, - tokenX, - tokenY, - p.version, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON lb_pair = l.contract_address - WHERE - topics [0] :: STRING = '0xad7d6f97abf51ce18e17a38f4d70e975be9c0708474987bb3e26ad21bd93ca70' --Swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - sender_address AS sender, - to_address AS tx_to, - id, - amount0In, - amount1In, - amount0Out, - amount1Out, - volatilityAccumulated AS volatility_accumulated, - fee0, - fee1, - protocolFee0 AS protocol_fee0, - protocolFee1 AS protocol_fee1, - tokenX, - tokenY, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN tokenX - WHEN amount0In <> 0 THEN tokenY - WHEN amount1In <> 0 THEN tokenX - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN tokenY - WHEN amount1Out <> 0 THEN tokenX - END AS token_out, - 'Swap' AS event_name, - 'trader-joe-v2' AS platform, - version, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.yml b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.yml deleted file mode 100644 index 67b54c9..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_1_swaps.yml +++ /dev/null @@ -1,84 +0,0 @@ -version: 2 -models: - - name: silver_dex__trader_joe_v2_1_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: VERSION - tests: - - not_null - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql deleted file mode 100644 index 963854c..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.sql +++ /dev/null @@ -1,82 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'lb_pair', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS tokenX, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tokenY, - utils.udf_hex_to_int( - topics [3] :: STRING - ) :: INT AS binStep, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS lb_pair, - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INT AS pool_id, - CASE - WHEN contract_address = '0x1886d09c9ade0c5db822d85d21678db67b6c2982' THEN 'v2' - WHEN contract_address = '0xb43120c4745967fa9b93e79c149e66b0f2d6fe0c' THEN 'v2.2' - ELSE 'v2.1' - END AS version, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - contract_address IN ( - '0x1886d09c9ade0c5db822d85d21678db67b6c2982', - --v2 - '0x8e42f2f4101563bf679975178e880fd87d3efd4e', - --v2.1 - '0xee0616a2deaa5331e2047bc61e0b588195a49cea', - --v2.1 - '0x8597db3ba8de6baadeda8cba4dac653e24a0e57b', - --v2.1 - '0xb43120c4745967fa9b93e79c149e66b0f2d6fe0c' --v2.2 - ) - AND topics [0] :: STRING = '0x2c8d104b27c6b7f4492017a6f5cf3803043688934ebcaa6a03540beeaf976aff' --LB PairCreated - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - tokenX, - tokenY, - binStep AS bin_step, - lb_pair, - pool_id, - version, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY lb_pair -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.yml b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.yml deleted file mode 100644 index 42cae15..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__trader_joe_v2_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - LB_PAIR - columns: - - name: LB_PAIR - tests: - - not_null - - name: TOKENX - tests: - - not_null - - name: TOKENY - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql deleted file mode 100644 index 7e16dbf..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.sql +++ /dev/null @@ -1,122 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - lb_pair, - tokenX, - tokenY - FROM - {{ ref('silver_dex__trader_joe_v2_pools') }} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - l.origin_function_signature, - l.origin_from_address, - l.origin_to_address, - l.event_index, - l.contract_address, - l.topics, - l.data, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS recipient_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l.topics [3] :: STRING - ) - ) AS id, - CASE - WHEN utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) = 0 THEN FALSE - ELSE TRUE - END AS swapForY, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS amountIn, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS amountOut, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS volatilityAccumulated, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [4] :: STRING - ) - ) AS fees, - CASE - WHEN swapForY THEN tokenY - ELSE tokenX - END AS token_out_address, - CASE - WHEN swapForY THEN tokenX - ELSE tokenY - END AS token_in_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON lb_pair = l.contract_address - WHERE - topics [0] :: STRING = '0xc528cda9e500228b16ce84fadae290d9a49aecb17483110004c5af0a07f6fd73' --Swap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - sender_address AS sender, - recipient_address AS tx_to, - id, - swapForY AS swap_for_y, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - volatilityAccumulated AS volatility_accumulated, - fees, - token_in_address AS token_in, - token_out_address AS token_out, - 'Swap' AS event_name, - 'trader-joe-v2' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base diff --git a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.yml b/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.yml deleted file mode 100644 index e617d4c..0000000 --- a/models/silver/defi/dex/trader_joe/silver_dex__trader_joe_v2_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__trader_joe_v2_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql b/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql deleted file mode 100644 index e65ced8..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.sql +++ /dev/null @@ -1,62 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INT AS pool_id, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address = LOWER('0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9') - AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - pool_id, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.yml b/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.yml deleted file mode 100644 index 053b3fc..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ2_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__univ2_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql b/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql deleted file mode 100644 index ae9ca4e..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.sql +++ /dev/null @@ -1,124 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__univ2_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) :: INTEGER - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INTEGER - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) :: INTEGER - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) :: INTEGER - ) AS amount1Out, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender, - tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'uniswap-v2' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.yml b/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.yml deleted file mode 100644 index 55ba509..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ2_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__univ2_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 #might be normal for swaps not to happen on a day - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql b/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql deleted file mode 100644 index 99a9428..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.sql +++ /dev/null @@ -1,108 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - cluster_by = ['_inserted_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH created_pools AS ( - - SELECT - block_number AS created_block, - block_timestamp AS created_time, - tx_hash AS created_tx_hash, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - LOWER(CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))) AS token0_address, - LOWER(CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))) AS token1_address, - utils.udf_hex_to_int( - 's2c', - topics [3] :: STRING - ) :: INTEGER AS fee, - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) :: INTEGER AS tick_spacing, - CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' - AND contract_address = '0x1f98431c8ad98523631ae4a59f267346ea31f984' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -initial_info AS ( - SELECT - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS init_sqrtPriceX96, - utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [1] :: STRING)) :: FLOAT AS init_tick, - pow( - 1.0001, - init_tick - ) AS init_price_1_0_unadj - FROM - {{ ref('core__fact_event_logs') }} - WHERE - topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' - AND tx_succeeded - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -FINAL AS ( - SELECT - created_block, - created_time, - created_tx_hash, - p.contract_address, - token0_address, - token1_address, - fee :: INTEGER AS fee, - ( - fee / 10000 - ) :: FLOAT AS fee_percent, - tick_spacing, - pool_address, - COALESCE( - init_tick, - 0 - ) AS init_tick, - p._log_id, - p._inserted_timestamp - FROM - created_pools p - LEFT JOIN initial_info i - ON p.pool_address = i.contract_address -) -SELECT - * -FROM - FINAL qualify(ROW_NUMBER() over(PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.yml b/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.yml deleted file mode 100644 index 702169b..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_pools.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: 2 -models: - - name: silver_dex__univ3_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: CREATED_BLOCK - tests: - - not_null - - name: CREATED_TIME - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 7 - - name: FEE - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - number - - name: INIT_TICK - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: TICK_SPACING - tests: - - not_null - - name: CREATED_TX_HASH - tests: - - not_null - - - diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql b/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql deleted file mode 100644 index fbe1647..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.sql +++ /dev/null @@ -1,101 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH base_swaps AS ( - - SELECT - *, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS recipient, - utils.udf_hex_to_int( - 's2c', - segmented_data [0] :: STRING - ) :: FLOAT AS amount0_unadj, - utils.udf_hex_to_int( - 's2c', - segmented_data [1] :: STRING - ) :: FLOAT AS amount1_unadj, - utils.udf_hex_to_int( - 's2c', - segmented_data [2] :: STRING - ) :: FLOAT AS sqrtPriceX96, - utils.udf_hex_to_int( - 's2c', - segmented_data [3] :: STRING - ) :: FLOAT AS liquidity, - utils.udf_hex_to_int( - 's2c', - segmented_data [4] :: STRING - ) :: FLOAT AS tick - FROM - {{ ref('core__fact_event_logs') }} - WHERE - block_timestamp :: DATE > '2021-04-01' - AND topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_succeeded - AND event_removed = 'false' - -{% if is_incremental() %} -AND modified_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND modified_timestamp >= SYSDATE() - INTERVAL '7 day' -{% endif %} -), -pool_data AS ( - SELECT - token0_address, - token1_address, - fee, - fee_percent, - tick_spacing, - pool_address - FROM - {{ ref('silver_dex__univ3_pools') }} -), -FINAL AS ( - SELECT - block_number, - block_timestamp, - tx_hash, - contract_address AS pool_address, - recipient, - sender, - fee, - tick, - tick_spacing, - liquidity, - event_index, - token0_address, - token1_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - amount0_unadj, - amount1_unadj - FROM - base_swaps - INNER JOIN pool_data - ON pool_data.pool_address = base_swaps.contract_address -) -SELECT - * -FROM - FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.yml b/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.yml deleted file mode 100644 index 6097abd..0000000 --- a/models/silver/defi/dex/uniswap/silver_dex__univ3_swaps.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: 2 -models: - - name: silver_dex__univ3_swaps - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: AMOUNT0_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: AMOUNT1_UNADJ - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: BLOCK_NUMBER - tests: - - not_null - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 1 - - name: LIQUIDITY - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - decimal - - float - - name: EVENT_INDEX - tests: - - not_null - - name: POOL_ADDRESS - tests: - - not_null - - name: RECIPIENT - tests: - - not_null - - name: SENDER - tests: - - not_null - - name: TICK - tests: - - not_null - - name: TX_HASH - tests: - - not_null \ No newline at end of file diff --git a/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql b/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql deleted file mode 100644 index 7c11fda..0000000 --- a/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.sql +++ /dev/null @@ -1,228 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH router_swaps_base AS ( - - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS from_token, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_token, - CONCAT('0x', SUBSTR(l.topics [3] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS swapType, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS fromAmount, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS toAmount, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [3] :: STRING, - 25, - 40 - ) - ) AS from_address, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [4] :: STRING, - 25, - 40 - ) - ) AS rebateTo, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - WHERE - contract_address IN ( - '0xcdfd61a8303beb5c8dd2a6d02df8d228ce15b9f3', - '0x9aed3a8896a85fe9a8cac52c9b402d092b629a30', - '0xd2635bc7e4e4f63b2892ed80d0b0f9dff7eda899', - '0x4c4af8dbc524681930a27b2f1af5bcc8062e6fb7', - --v2 - '0xb130a49065178465931d4f887056328cea5d723f' - ) --v3 - AND topics [0] :: STRING = '0x27c98e911efdd224f4002f6cd831c3ad0d2759ee176f9ee8466d95826af22a1c' --WooRouterSwap - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -), -swaps_base AS ( - SELECT - l.block_number, - l.block_timestamp, - l.tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - l.event_index, - l.contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS from_token, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS to_token, - CONCAT('0x', SUBSTR(l.topics [3] :: STRING, 27, 40)) AS to_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [0] :: STRING - ) - ) AS fromAmount, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [1] :: STRING - ) - ) AS toAmount, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [2] :: STRING, - 25, - 40 - ) - ) AS from_address, - CONCAT( - '0x', - SUBSTR( - l_segmented_data [3] :: STRING, - 25, - 40 - ) - ) AS rebateTo, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - WHERE - contract_address IN ( - '0x39d361e66798155813b907a70d6c2e3fdafb0877', - '0xc04362cf21e6285e295240e30c056511df224cf4', - '0x86b1742a1d7c963d3e8985829d722725316abf0a', - '0xeff23b4be1091b53205e35f3afcd9c7182bf3062', - '0xb89a33227876aef02a7ebd594af9973aece2f521', - '0x8693f9701d6db361fe9cc15bc455ef4366e39ae0', - '0x1f79f8a65e02f8a137ce7f79c038cc44332df448', - '0xed9e3f98bbed560e66b89aac922e29d4596a9642' - ) - AND topics [0] :: STRING IN ( - '0x74ef34e2ea7c5d9f7b7ed44e97ad44b4303416c3a660c3fb5b3bdb95a1d6abd3', - '0x0e8e403c2d36126272b08c75823e988381d9dc47f2f0a9a080d95f891d95c469' - ) --WooSwap - AND tx_hash NOT IN ( - SELECT - tx_hash - FROM - router_swaps_base - ) - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - CASE - WHEN from_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE from_token - END AS token_in, - CASE - WHEN to_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE to_token - END AS token_out, - to_address AS tx_to, - swapType AS swap_type, - fromAmount AS amount_in_unadj, - toAmount AS amount_out_unadj, - from_address AS sender, - rebateTo AS rebate_to, - 'WooRouterSwap' AS event_name, - 'woofi' AS platform, - _log_id, - _inserted_timestamp -FROM - router_swaps_base -UNION ALL -SELECT - block_number, - block_timestamp, - tx_hash, - origin_function_signature, - origin_from_address, - origin_to_address, - event_index, - contract_address, - CASE - WHEN from_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE from_token - END AS token_in, - CASE - WHEN to_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' - ELSE to_token - END AS token_out, - to_address AS tx_to, - NULL AS swap_type, - fromAmount AS amount_in_unadj, - toAmount AS amount_out_unadj, - from_address AS sender, - rebateTo AS rebate_to, - 'WooSwap' AS event_name, - 'woofi' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base diff --git a/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.yml b/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.yml deleted file mode 100644 index 3827713..0000000 --- a/models/silver/defi/dex/woofi/silver_dex__woofi_swaps.yml +++ /dev/null @@ -1,81 +0,0 @@ -version: 2 -models: - - name: silver_dex__woofi_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SENDER - tests: - - not_null: - where: BLOCK_TIMESTAMP > '2021-08-01' - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ \ No newline at end of file diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.sql b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.sql deleted file mode 100644 index e606047..0000000 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.sql +++ /dev/null @@ -1,66 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'pool_address', - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pool_creation AS ( - - SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1, - CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref ('core__fact_event_logs') }} - WHERE - contract_address IN ( - '0xac2ee06a14c52570ef3b9812ed240bce359772e7', - --v2 - '0x9c2abd632771b433e5e7507bcaa41ca3b25d8544' - ) --v3 - AND topics [0] :: STRING IN ( - '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9', - --PairCreated v2 - '0x91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db' - ) --v3 - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - tx_hash, - contract_address, - event_index, - token0, - token1, - pool_address, - _log_id, - _inserted_timestamp -FROM - pool_creation qualify(ROW_NUMBER() over (PARTITION BY pool_address -ORDER BY - _inserted_timestamp DESC)) = 1 diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.yml b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.yml deleted file mode 100644 index 5fcab4a..0000000 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_pools.yml +++ /dev/null @@ -1,23 +0,0 @@ -version: 2 -models: - - name: silver_dex__zyberswap_pools - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - POOL_ADDRESS - columns: - - name: POOL_ADDRESS - tests: - - not_null - - name: TOKEN0 - tests: - - not_null - - name: TOKEN1 - tests: - - not_null - - name: _INSERTED_TIMESTAMP - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ \ No newline at end of file diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.sql b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.sql deleted file mode 100644 index 317cb1d..0000000 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.sql +++ /dev/null @@ -1,124 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__zyberswap_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) :: INTEGER - ) AS amount0In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [1] :: STRING - ) :: INTEGER - ) AS amount1In, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [2] :: STRING - ) :: INTEGER - ) AS amount0Out, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - segmented_data [3] :: STRING - ) :: INTEGER - ) AS amount1Out, - CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender, - CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to, - token0, - token1, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender, - tx_to, - amount0In, - amount1In, - amount0Out, - amount1Out, - token0, - token1, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN amount1In - WHEN amount0In <> 0 THEN amount0In - WHEN amount1In <> 0 THEN amount1In - END AS amount_in_unadj, - CASE - WHEN amount0Out <> 0 THEN amount0Out - WHEN amount1Out <> 0 THEN amount1Out - END AS amount_out_unadj, - CASE - WHEN amount0In <> 0 - AND amount1In <> 0 - AND amount0Out <> 0 THEN token1 - WHEN amount0In <> 0 THEN token0 - WHEN amount1In <> 0 THEN token1 - END AS token_in, - CASE - WHEN amount0Out <> 0 THEN token0 - WHEN amount1Out <> 0 THEN token1 - END AS token_out, - 'Swap' AS event_name, - 'zyberswap-v2' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base -WHERE - token_in <> token_out diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.yml b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.yml deleted file mode 100644 index 991a214..0000000 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v2_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__zyberswap_v2_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.sql b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.sql deleted file mode 100644 index a92d060..0000000 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.sql +++ /dev/null @@ -1,122 +0,0 @@ -{{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'block_number', - cluster_by = ['block_timestamp::DATE'], - tags = ['silver_dex','defi','dex','curated'] -) }} - -WITH pools AS ( - - SELECT - pool_address, - token0, - token1 - FROM - {{ ref('silver_dex__zyberswap_pools') }} -), -swaps_base AS ( - SELECT - block_number, - origin_function_signature, - origin_from_address, - origin_to_address, - block_timestamp, - tx_hash, - event_index, - contract_address, - regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS l_segmented_data, - CONCAT('0x', SUBSTR(l.topics [1] :: STRING, 27, 40)) AS sender_address, - CONCAT('0x', SUBSTR(l.topics [2] :: STRING, 27, 40)) AS reipient_address, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [0] :: STRING - ) - ) AS amount0, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [1] :: STRING - ) - ) AS amount1, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [2] :: STRING - ) - ) AS sqrtP, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - l_segmented_data [3] :: STRING - ) - ) AS liquidity, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - 's2c', - l_segmented_data [4] :: STRING - ) - ) AS currentTick, - ABS(GREATEST(amount0, amount1)) AS amountOut, - ABS(LEAST(amount0, amount1)) AS amountIn, - token0, - token1, - CASE - WHEN amount0 < 0 THEN token0 - ELSE token1 - END AS token_in, - CASE - WHEN amount0 > 0 THEN token0 - ELSE token1 - END AS token_out, - CONCAT( - tx_hash :: STRING, - '-', - event_index :: STRING - ) AS _log_id, - modified_timestamp AS _inserted_timestamp - FROM - {{ ref('core__fact_event_logs') }} - l - INNER JOIN pools p - ON p.pool_address = contract_address - WHERE - topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' - AND tx_succeeded - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day' - -{% endif %} -) -SELECT - block_number, - block_timestamp, - origin_function_signature, - origin_from_address, - origin_to_address, - tx_hash, - event_index, - contract_address, - sender_address AS sender, - reipient_address AS tx_to, - amount0, - amount1, - sqrtP, - liquidity, - currentTick, - amountIn AS amount_in_unadj, - amountOut AS amount_out_unadj, - token_in, - token_out, - 'Swap' AS event_name, - 'zyberswap-v3' AS platform, - _log_id, - _inserted_timestamp -FROM - swaps_base diff --git a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.yml b/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.yml deleted file mode 100644 index aa93fe1..0000000 --- a/models/silver/defi/dex/zyberswap/silver_dex__zyberswap_v3_swaps.yml +++ /dev/null @@ -1,116 +0,0 @@ -version: 2 -models: - - name: silver_dex__zyberswap_v3_swaps - - tests: - - dbt_utils.unique_combination_of_columns: - combination_of_columns: - - _LOG_ID - columns: - - name: BLOCK_NUMBER - tests: - - not_null - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: BLOCK_TIMESTAMP - tests: - - not_null - - dbt_expectations.expect_row_values_to_have_recent_data: - datepart: day - interval: 2 - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - TIMESTAMP_LTZ - - TIMESTAMP_NTZ - - name: TX_HASH - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: CONTRACT_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: AMOUNT_IN_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT_UNADJ - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: AMOUNT_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: TOKEN_IN - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - - name: TOKEN_OUT - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: SYMBOL_IN - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: SYMBOL_OUT - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: TX_TO - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: PLATFORM - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - STRING - - VARCHAR - - name: EVENT_INDEX - tests: - - dbt_expectations.expect_column_values_to_be_in_type_list: - column_type_list: - - NUMBER - - FLOAT - - name: _LOG_ID - tests: - - not_null - - name: ORIGIN_FUNCTION_SIGNATURE - tests: - - not_null - - name: ORIGIN_FROM_ADDRESS - tests: - - not_null - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - - name: ORIGIN_TO_ADDRESS - tests: - - dbt_expectations.expect_column_values_to_match_regex: - regex: 0[xX][0-9a-fA-F]+ - diff --git a/packages.yml b/packages.yml index 3f2b3d2..76cf83f 100644 --- a/packages.yml +++ b/packages.yml @@ -1,3 +1,3 @@ packages: - git: https://github.com/FlipsideCrypto/fsc-evm.git - revision: v4.8.2 \ No newline at end of file + revision: v4.9.2