Skip to content

Commit

Permalink
AN-4558/add-univ2-to-all-evms (#146)
Browse files Browse the repository at this point in the history
* add univ2 and heal models

* quick fixes

* fix label

* add liq heal + fixes
  • Loading branch information
mattromano authored Mar 7, 2024
1 parent d6bc9c4 commit 8919a42
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ curve AS (
FROM
{{ ref('silver_dex__curve_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'curve' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -106,7 +106,7 @@ balancer AS (
FROM
{{ ref('silver_dex__balancer_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'balancer' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -134,7 +134,34 @@ uni_v3 AS (
FROM
{{ ref('silver_dex__univ3_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'uni_v3' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
),
uni_v2 AS (

SELECT
block_number,
block_timestamp,
tx_hash,
contract_address,
pool_address,
NULL AS pool_name,
token0,
token1,
'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_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -162,7 +189,7 @@ dackieswap AS (
FROM
{{ ref('silver_dex__dackie_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'dackieswap' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -190,7 +217,7 @@ sushi AS (
FROM
{{ ref('silver_dex__sushi_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'sushi' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -217,7 +244,7 @@ maverick AS (
FROM
{{ ref('silver_dex__maverick_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'maverick' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -244,7 +271,7 @@ swapbased AS (
FROM
{{ ref('silver_dex__swapbased_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'swapbased' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -271,7 +298,7 @@ aerodrome AS (
FROM
{{ ref('silver_dex__aerodrome_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'aerodrome' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -298,7 +325,7 @@ baseswap AS (
FROM
{{ ref('silver_dex__baseswap_pools') }}

{% if is_incremental() %}
{% if is_incremental() and 'baseswap' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -319,6 +346,11 @@ all_pools_standard AS (
FROM
swapbased
UNION ALL
SELECT
*
FROM
uni_v2
UNION ALL
SELECT
*
FROM
Expand Down
116 changes: 99 additions & 17 deletions models/silver/defi/dex/silver_dex__complete_dex_swaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ curve_swaps AS (
'null'
) <> COALESCE(token_symbol_out, 'null')

{% if is_incremental() %}
{% if is_incremental() and 'curve_swaps' not in var('HEAL_CURATED_MODEL') %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '36 hours'
Expand Down Expand Up @@ -192,7 +192,7 @@ dackie_swaps AS (
block_timestamp
) = p2.hour

{% if is_incremental() %}
{% if is_incremental() and 'dackie_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -294,7 +294,59 @@ univ3_swaps AS (
block_timestamp
) = p2.hour

{% if is_incremental() %}
{% if is_incremental() and 'univ3_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '36 hours'
FROM
{{ this }}
)
{% endif %}
),
univ2_swaps AS (
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
event_name,
c1.decimals AS decimals_in,
c1.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,
c2.decimals AS decimals_out,
c2.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,
sender,
tx_to,
event_index,
platform,
'v2' AS version,
token_in,
token_out,
NULL AS pool_name,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver_dex__univ2_swaps') }}
s
LEFT JOIN contracts c1
ON s.token_in = c1.address
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() and 'univ2_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -396,7 +448,7 @@ sushi_swaps AS (
block_timestamp
) = p2.hour

{% if is_incremental() %}
{% if is_incremental() and 'sushi_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -448,7 +500,7 @@ maverick_swaps AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'maverick_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -522,7 +574,7 @@ woofi_swaps AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'woofi_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -574,7 +626,7 @@ balancer_swaps AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'balancer_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -584,7 +636,7 @@ WHERE
)
{% endif %}
),
baseswap AS (
baseswap_swaps AS (
SELECT
block_number,
block_timestamp,
Expand Down Expand Up @@ -626,7 +678,7 @@ baseswap AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'baseswap_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -636,7 +688,7 @@ WHERE
)
{% endif %}
),
swapbased AS (
swapbased_swaps AS (
SELECT
block_number,
block_timestamp,
Expand Down Expand Up @@ -678,7 +730,7 @@ swapbased AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'swapbased_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand All @@ -688,7 +740,7 @@ WHERE
)
{% endif %}
),
aerodrome AS (
aerodrome_swaps AS (
SELECT
block_number,
block_timestamp,
Expand Down Expand Up @@ -730,7 +782,7 @@ aerodrome AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'aerodrome_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -792,7 +844,7 @@ voodoo_swaps AS (
LEFT JOIN contracts c2
ON s.token_out = c2.address

{% if is_incremental() %}
{% if is_incremental() and 'voodoo_swaps' not in var('HEAL_CURATED_MODEL') %}
WHERE
_inserted_timestamp >= (
SELECT
Expand Down Expand Up @@ -832,7 +884,37 @@ all_dex_standard AS (
_log_id,
_inserted_timestamp
FROM
swapbased
swapbased_swaps
UNION ALL
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_out_unadj,
amount_in,
amount_out,
sender,
tx_to,
event_index,
platform,
version,
token_in,
token_out,
symbol_in,
symbol_out,
decimals_in,
decimals_out,
_log_id,
_inserted_timestamp
FROM
univ2_swaps
UNION ALL
SELECT
block_number,
Expand Down Expand Up @@ -862,7 +944,7 @@ all_dex_standard AS (
_log_id,
_inserted_timestamp
FROM
aerodrome
aerodrome_swaps
UNION ALL
SELECT
block_number,
Expand Down Expand Up @@ -892,7 +974,7 @@ all_dex_standard AS (
_log_id,
_inserted_timestamp
FROM
baseswap
baseswap_swaps
UNION ALL
SELECT
block_number,
Expand Down
Loading

0 comments on commit 8919a42

Please sign in to comment.