From 8f713fb14490d0d5c1e076002dc673df32849aa3 Mon Sep 17 00:00:00 2001 From: drethereum <71602799+drethereum@users.noreply.github.com> Date: Mon, 20 May 2024 11:14:17 -0700 Subject: [PATCH] explcit alias (#172) --- ...ilver_bridge__complete_bridge_activity.sql | 72 ++++++++--------- ...lver_dex__complete_dex_liquidity_pools.sql | 51 ++++++------ .../dex/silver_dex__complete_dex_swaps.sql | 77 +++++++++++-------- .../silver__complete_lending_borrows.sql | 23 +++++- .../silver__complete_lending_deposits.sql | 23 +++++- .../silver__complete_lending_flashloans.sql | 29 ++++++- .../silver__complete_lending_liquidations.sql | 26 ++++++- .../silver__complete_lending_repayments.sql | 24 +++++- .../silver__complete_lending_withdraws.sql | 23 +++++- 9 files changed, 239 insertions(+), 109 deletions(-) diff --git a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql b/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql index 7154ecb..b90908e 100644 --- a/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql +++ b/models/silver/defi/bridge/silver_bridge__complete_bridge_activity.sql @@ -600,44 +600,20 @@ heal_model AS ( sender, receiver, destination_chain_receiver, - CASE - WHEN platform IN ( - 'stargate', - 'wormhole', - 'meson' - ) 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 platform IN ( - 'stargate', - 'wormhole', - 'meson' - ) THEN LOWER(destination_chain) - WHEN d.chain IS NULL THEN LOWER(destination_chain) - ELSE LOWER( - d.chain - ) - END AS destination_chain, + destination_chain_id, + destination_chain, t0.token_address, - CASE - WHEN platform = 'axelar' THEN COALESCE( - C.token_symbol, - t0.token_symbol - ) - ELSE C.token_symbol - END AS token_symbol, + 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, + END AS amount_heal, CASE - WHEN C.token_decimals IS NOT NULL THEN amount * p.price + WHEN C.token_decimals IS NOT NULL THEN amount_heal * p.price ELSE NULL - END AS amount_usd, + END AS amount_usd_heal, _id, t0._inserted_timestamp FROM @@ -652,17 +628,6 @@ heal_model AS ( 'hour', block_timestamp ) = p.hour - LEFT JOIN {{ source( - 'external_gold_defillama', - 'dim_chains' - ) }} - d - ON d.chain_id :: STRING = t0.destination_chain_id :: STRING - OR LOWER( - d.chain - ) = LOWER( - t0.destination_chain - ) WHERE CONCAT( t0.block_number, @@ -764,7 +729,30 @@ heal_model AS ( ) %} 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, + _id, + _inserted_timestamp FROM heal_model {% endif %} 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 index 0f4f201..e3cc06e 100644 --- a/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.sql +++ b/models/silver/defi/dex/silver_dex__complete_dex_liquidity_pools.sql @@ -755,7 +755,7 @@ heal_model AS ( CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42)) ) ) - END AS pool_name, + END AS pool_name_heal, fee, tick_spacing, token0, @@ -766,24 +766,7 @@ heal_model AS ( token5, token6, token7, - OBJECT_CONSTRUCT( - 'token0', - token0, - 'token1', - token1, - 'token2', - token2, - 'token3', - token3, - 'token4', - token4, - 'token5', - token5, - 'token6', - token6, - 'token7', - token7 - ) AS tokens, + tokens, OBJECT_CONSTRUCT( 'token0', c0.token_symbol, @@ -801,7 +784,7 @@ heal_model AS ( c6.token_symbol, 'token7', c7.token_symbol - ) AS symbols, + ) AS symbols_heal, OBJECT_CONSTRUCT( 'token0', c0.token_decimals, @@ -819,7 +802,7 @@ heal_model AS ( c6.token_decimals, 'token7', c7.token_decimals - ) AS decimals, + ) AS decimals_heal, platform, version, _id, @@ -1178,7 +1161,29 @@ heal_model AS ( ) %} 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 %} @@ -1214,4 +1219,4 @@ SELECT SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id FROM - FINAL \ No newline at end of file + FINAL diff --git a/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql b/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql index 1e8637c..e71fb41 100644 --- a/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql +++ b/models/silver/defi/dex/silver_dex__complete_dex_swaps.sql @@ -4,7 +4,7 @@ incremental_strategy = 'delete+insert', unique_key = ['block_number','platform','version'], cluster_by = ['block_timestamp::DATE'], - tags = ['curated','reorg'] + tags = ['curated','reorg','heal'] ) }} WITH univ2 AS ( @@ -664,66 +664,54 @@ heal_model AS ( event_name, token_in, c1.token_decimals AS decimals_in, - CASE - WHEN t0.platform = 'curve' THEN COALESCE( - c1.token_symbol, - t0.symbol_in - ) - ELSE t0.symbol_in - END AS symbol_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, + 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 decimals_in IS NOT NULL THEN amount_in * p1.price + WHEN c1.token_decimals IS NOT NULL THEN amount_in_heal * p1.price ELSE NULL - END AS amount_in_usd, + END AS amount_in_usd_heal, token_out, c2.token_decimals AS decimals_out, - CASE - WHEN t0.platform = 'curve' THEN COALESCE( - c2.token_symbol, - t0.symbol_out - ) - ELSE t0.symbol_out - END AS symbol_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, + 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 decimals_out IS NOT NULL THEN amount_out * p2.price + WHEN c2.token_decimals IS NOT NULL THEN amount_out_heal * p2.price ELSE NULL - END AS amount_out_usd, + END AS amount_out_usd_heal, CASE WHEN lp.pool_name IS NULL THEN CONCAT( LEAST( COALESCE( - symbol_in, + c1.token_symbol, CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42)) ), COALESCE( - symbol_out, + c2.token_symbol, CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)) ) ), '-', GREATEST( COALESCE( - symbol_in, + c1.token_symbol, CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42)) ), COALESCE( - symbol_out, + c2.token_symbol, CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42)) ) ) ) ELSE lp.pool_name - END AS pool_name, + END AS pool_name_heal, sender, tx_to, event_index, @@ -944,7 +932,34 @@ heal_model AS ( ) %} UNION ALL SELECT - * + block_number, + block_timestamp, + tx_hash, + origin_function_signature, + origin_from_address, + origin_to_address, + contract_address, + event_name, + token_in, + decimals_in, + symbol_in, + amount_in_unadj, + amount_in_heal AS amount_in, + amount_in_usd_heal AS amount_in_usd, + token_out, + 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, + version, + _log_id, + _inserted_timestamp FROM heal_model {% endif %} diff --git a/models/silver/defi/lending/complete_lending/silver__complete_lending_borrows.sql b/models/silver/defi/lending/complete_lending/silver__complete_lending_borrows.sql index 5b4a607..6ec1aa1 100644 --- a/models/silver/defi/lending/complete_lending/silver__complete_lending_borrows.sql +++ b/models/silver/defi/lending/complete_lending/silver__complete_lending_borrows.sql @@ -311,7 +311,7 @@ heal_model AS ( ROUND( amount * p.price, 2 - ) AS amount_usd, + ) AS amount_usd_heal, platform, t0.blockchain, t0._LOG_ID, @@ -383,7 +383,26 @@ FINAL AS ( ) %} UNION ALL SELECT - * + tx_hash, + block_number, + block_timestamp, + event_index, + origin_from_address, + origin_to_address, + origin_function_signature, + contract_address, + event_name, + borrower, + protocol_market, + token_address, + token_symbol, + amount_unadj, + amount, + amount_usd_heal AS amount_usd, + platform, + blockchain, + _LOG_ID, + _INSERTED_TIMESTAMP FROM heal_model {% endif %} diff --git a/models/silver/defi/lending/complete_lending/silver__complete_lending_deposits.sql b/models/silver/defi/lending/complete_lending/silver__complete_lending_deposits.sql index 9064a07..bcae875 100644 --- a/models/silver/defi/lending/complete_lending/silver__complete_lending_deposits.sql +++ b/models/silver/defi/lending/complete_lending/silver__complete_lending_deposits.sql @@ -304,7 +304,7 @@ heal_model AS ( ROUND( amount * p.price, 2 - ) AS amount_usd, + ) AS amount_usd_heal, platform, t0.blockchain, t0._LOG_ID, @@ -376,7 +376,26 @@ FINAL AS ( ) %} UNION ALL SELECT - * + tx_hash, + block_number, + block_timestamp, + event_index, + origin_from_address, + origin_to_address, + origin_function_signature, + contract_address, + event_name, + protocol_market, + depositor, + token_address, + token_symbol, + amount_unadj, + amount, + amount_usd_heal AS amount_usd, + platform, + blockchain, + _LOG_ID, + _INSERTED_TIMESTAMP FROM heal_model {% endif %} diff --git a/models/silver/defi/lending/complete_lending/silver__complete_lending_flashloans.sql b/models/silver/defi/lending/complete_lending/silver__complete_lending_flashloans.sql index b5b040b..9eb2bf6 100644 --- a/models/silver/defi/lending/complete_lending/silver__complete_lending_flashloans.sql +++ b/models/silver/defi/lending/complete_lending/silver__complete_lending_flashloans.sql @@ -199,13 +199,13 @@ heal_model AS ( ROUND( flashloan_amount * p.price, 2 - ) AS flashloan_amount_usd, + ) AS flashloan_amount_usd_heal, premium_amount_unadj, premium_amount, ROUND( premium_amount * p.price, 2 - ) AS premium_amount_usd, + ) AS premium_amount_usd_heal, platform, t0.blockchain, t0._LOG_ID, @@ -319,7 +319,30 @@ FINAL AS ( ) %} UNION ALL SELECT - * + tx_hash, + block_number, + block_timestamp, + event_index, + origin_from_address, + origin_to_address, + origin_function_signature, + contract_address, + event_name, + protocol_market, + initiator, + target, + flashloan_token, + flashloan_token_symbol, + flashloan_amount_unadj, + flashloan_amount, + flashloan_amount_usd_heal AS flashloan_amount_usd, + premium_amount_unadj, + premium_amount, + premium_amount_usd_heal AS premium_amount_usd, + platform, + blockchain, + _LOG_ID, + _INSERTED_TIMESTAMP FROM heal_model {% endif %} diff --git a/models/silver/defi/lending/complete_lending/silver__complete_lending_liquidations.sql b/models/silver/defi/lending/complete_lending/silver__complete_lending_liquidations.sql index e11c53f..cc2f9eb 100644 --- a/models/silver/defi/lending/complete_lending/silver__complete_lending_liquidations.sql +++ b/models/silver/defi/lending/complete_lending/silver__complete_lending_liquidations.sql @@ -346,7 +346,7 @@ heal_model AS ( amount_usd, 2 ) - END AS amount_usd, + END AS amount_usd_heal, debt_token, debt_token_symbol, platform, @@ -420,7 +420,29 @@ FINAL AS ( ) %} UNION ALL SELECT - * + tx_hash, + block_number, + block_timestamp, + event_index, + origin_from_address, + origin_to_address, + origin_function_signature, + contract_address, + event_name, + liquidator, + borrower, + protocol_market, + collateral_token, + collateral_token_symbol, + amount_unadj, + amount, + amount_usd_heal AS amount_usd, + debt_token, + debt_token_symbol, + platform, + blockchain, + _LOG_ID, + _INSERTED_TIMESTAMP FROM heal_model {% endif %} diff --git a/models/silver/defi/lending/complete_lending/silver__complete_lending_repayments.sql b/models/silver/defi/lending/complete_lending/silver__complete_lending_repayments.sql index c1f87e4..445a573 100644 --- a/models/silver/defi/lending/complete_lending/silver__complete_lending_repayments.sql +++ b/models/silver/defi/lending/complete_lending/silver__complete_lending_repayments.sql @@ -311,7 +311,7 @@ heal_model AS ( ROUND( amount * p.price, 2 - ) AS amount_usd, + ) AS amount_usd_heal, platform, t0.blockchain, t0._LOG_ID, @@ -383,7 +383,27 @@ FINAL AS ( ) %} UNION ALL SELECT - * + tx_hash, + block_number, + block_timestamp, + event_index, + origin_from_address, + origin_to_address, + origin_function_signature, + contract_address, + event_name, + protocol_market, + payer, + borrower, + token_address, + token_symbol, + amount_unadj, + amount, + amount_usd_heal AS amount_usd, + platform, + blockchain, + _LOG_ID, + _INSERTED_TIMESTAMP FROM heal_model {% endif %} diff --git a/models/silver/defi/lending/complete_lending/silver__complete_lending_withdraws.sql b/models/silver/defi/lending/complete_lending/silver__complete_lending_withdraws.sql index 6d70e95..20f93c9 100644 --- a/models/silver/defi/lending/complete_lending/silver__complete_lending_withdraws.sql +++ b/models/silver/defi/lending/complete_lending/silver__complete_lending_withdraws.sql @@ -315,7 +315,7 @@ heal_model AS ( ROUND( amount * p.price, 2 - ) AS amount_usd, + ) AS amount_usd_heal, platform, t0.blockchain, t0._log_id, @@ -387,7 +387,26 @@ FINAL AS ( ) %} UNION ALL SELECT - * + tx_hash, + block_number, + block_timestamp, + event_index, + origin_from_address, + origin_to_address, + origin_function_signature, + contract_address, + event_name, + protocol_market, + depositor, + token_address, + token_symbol, + amount_unadj, + amount, + amount_usd_heal AS amount_usd, + platform, + blockchain, + _log_id, + _inserted_timestamp FROM heal_model {% endif %}