mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 11:47:03 +00:00
AN-4280/heal-logic (#366)
* vars * tx success * bridge heal * typo * cte name * lps heal * var format * heal logic * dex swaps heal * column names * round in gold
This commit is contained in:
parent
dc963455d5
commit
9514a0d7ff
59
README.md
59
README.md
@ -35,35 +35,43 @@ polygon:
|
||||
query_tag: <TAG>
|
||||
```
|
||||
|
||||
### Variables
|
||||
## Variables
|
||||
|
||||
To control the creation of UDF or SP macros with dbt run:
|
||||
* UPDATE_UDFS_AND_SPS
|
||||
When True, executes all macros included in the on-run-start hooks within dbt_project.yml on model run as normal
|
||||
When False, none of the on-run-start macros are executed on model run
|
||||
* Default values are False
|
||||
* When True, executes all macros included in the on-run-start hooks within dbt_project.yml on model run as normal
|
||||
* When False, none of the on-run-start macros are executed on model run
|
||||
|
||||
Default values are False
|
||||
* Usage: `dbt run --vars '{"UPDATE_UDFS_AND_SPS":True}' -m ...`
|
||||
|
||||
Use a variable to heal a model incrementally:
|
||||
* HEAL_MODEL
|
||||
* Default is FALSE (Boolean)
|
||||
* When FALSE, logic will be negated
|
||||
* When TRUE, heal logic will apply
|
||||
* Include `heal` in model tags within the config block for inclusion in the `dbt_run_heal_models` workflow, e.g. `tags = 'heal'`
|
||||
|
||||
* Usage: `dbt run --vars '{"HEAL_MODEL":True}' -m ...`
|
||||
|
||||
Use a variable to negate incremental logic:
|
||||
* Example use case: reload records in a curated complete table without a full-refresh, such as `silver_bridge.complete_bridge_activity`:
|
||||
* HEAL_MODELS
|
||||
* Default is an empty array []
|
||||
* When item is included in var array [], incremental logic will be skipped for that CTE / code block
|
||||
* When item is not included in var array [] or does not match specified item in model, incremental logic will apply
|
||||
* Example set up: `{% if is_incremental() and 'axelar' not in var('HEAL_MODELS') %}`
|
||||
|
||||
* Usage:
|
||||
dbt run --var '{"UPDATE_UDFS_AND_SPS":True}' -m ...
|
||||
* Single CTE: `dbt run --vars '{"HEAL_MODELS":"axelar"}' -m ...`
|
||||
* Multiple CTEs: `dbt run --vars '{"HEAL_MODELS":["axelar","across","celer_cbridge"]}' -m ...`
|
||||
|
||||
To reload records in a curated complete table without a full-refresh, such as `silver_bridge.complete_bridge_activity`:
|
||||
* HEAL_CURATED_MODEL
|
||||
Default is an empty array []
|
||||
When item is included in var array [], incremental logic will be skipped for that CTE / code block
|
||||
When item is not included in var array [] or does not match specified item in model, incremental logic will apply
|
||||
Example set up: `{% if is_incremental() and 'axelar' not in var('HEAL_CURATED_MODEL') %}`
|
||||
Use a variable to extend the incremental lookback period:
|
||||
* LOOKBACK
|
||||
* Default is a string representing the specified time interval e.g. '12 hours', '7 days' etc.
|
||||
* Example set up: `SELECT MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'`
|
||||
|
||||
* Usage:
|
||||
Single CTE: dbt run --var '{"HEAL_CURATED_MODEL":"axelar"}' -m ...
|
||||
Multiple CTEs: dbt run --var '{"HEAL_CURATED_MODEL":["axelar","across","celer_cbridge"]}' -m ...
|
||||
|
||||
### Resources:
|
||||
- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
|
||||
- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
|
||||
- Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support
|
||||
- Find [dbt events](https://events.getdbt.com) near you
|
||||
- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
|
||||
* Usage: `dbt run --vars '{"LOOKBACK":"36 hours"}' -m ...`
|
||||
|
||||
## Applying Model Tags
|
||||
|
||||
@ -97,7 +105,7 @@ To add/update a model's snowflake tags, add/modify the `meta` model property und
|
||||
By default, model tags are pushed to Snowflake on each load. You can disable this by setting the `UPDATE_SNOWFLAKE_TAGS` project variable to `False` during a run.
|
||||
|
||||
```
|
||||
dbt run --var '{"UPDATE_SNOWFLAKE_TAGS":False}' -s models/core/core__fact_blocks.sql
|
||||
dbt run --vars '{"UPDATE_SNOWFLAKE_TAGS":False}' -s models/core/core__fact_blocks.sql
|
||||
```
|
||||
|
||||
### Querying for existing tags on a model in snowflake
|
||||
@ -106,3 +114,10 @@ dbt run --var '{"UPDATE_SNOWFLAKE_TAGS":False}' -s models/core/core__fact_blocks
|
||||
select *
|
||||
from table(polygon.information_schema.tag_references('polygon.core.fact_blocks', 'table'));
|
||||
```
|
||||
|
||||
### Resources:
|
||||
- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
|
||||
- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
|
||||
- Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support
|
||||
- Find [dbt events](https://events.getdbt.com) near you
|
||||
- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
|
||||
@ -69,7 +69,7 @@ vars:
|
||||
BALANCES_START: 0
|
||||
BALANCES_END: 15000000
|
||||
HEAL_MODEL: False
|
||||
HEAL_CURATED_MODEL: []
|
||||
HEAL_MODELS: []
|
||||
DROP_UDFS_AND_SPS: False
|
||||
START_GHA_TASKS: False
|
||||
STUDIO_TEST_USER_ID: '{{ env_var("STUDIO_TEST_USER_ID", "98d15c30-9fa5-43cd-9c69-3d4c0bb269f5") }}'
|
||||
|
||||
@ -33,7 +33,13 @@ SELECT
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
ROUND(
|
||||
CASE
|
||||
WHEN amount_usd < 1e+15 THEN amount_usd
|
||||
ELSE NULL
|
||||
END,
|
||||
2
|
||||
) AS amount_usd,
|
||||
COALESCE (
|
||||
complete_bridge_activity_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
|
||||
@ -24,10 +24,26 @@ SELECT
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_in,
|
||||
amount_in_usd,
|
||||
ROUND(
|
||||
CASE
|
||||
WHEN 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,
|
||||
amount_out_usd,
|
||||
ROUND(
|
||||
CASE
|
||||
WHEN 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,
|
||||
|
||||
@ -38,13 +38,13 @@ WITH nft_base_models AS (
|
||||
FROM
|
||||
{{ ref('silver__seaport_1_1_sales') }}
|
||||
|
||||
{% if is_incremental() and 'seaport_1_1' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'seaport_1_1' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -80,13 +80,13 @@ SELECT
|
||||
FROM
|
||||
{{ ref('silver__seaport_1_4_sales') }}
|
||||
|
||||
{% if is_incremental() and 'seaport_1_4' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'seaport_1_4' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -122,13 +122,13 @@ SELECT
|
||||
FROM
|
||||
{{ ref('silver__seaport_1_5_sales') }}
|
||||
|
||||
{% if is_incremental() and 'seaport_1_5' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'seaport_1_5' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -164,13 +164,13 @@ SELECT
|
||||
FROM
|
||||
{{ ref('silver__tofunft_sales') }}
|
||||
|
||||
{% if is_incremental() and 'tofunft' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'tofunft' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -206,13 +206,13 @@ SELECT
|
||||
FROM
|
||||
{{ ref('silver__mooar_sales') }}
|
||||
|
||||
{% if is_incremental() and 'mooar' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'mooar' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -248,13 +248,13 @@ SELECT
|
||||
FROM
|
||||
{{ ref('silver__seaport_1_6_sales') }}
|
||||
|
||||
{% if is_incremental() and 'seaport_1_6' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'seaport_1_6' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -587,7 +587,7 @@ heal_model AS (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -615,7 +615,7 @@ heal_model AS (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -654,7 +654,7 @@ heal_model AS (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
|
||||
@ -41,7 +41,7 @@ WITH base AS (
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -360,7 +360,7 @@ heal_model AS (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
|
||||
@ -35,7 +35,7 @@ AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -169,7 +169,7 @@ heal_model AS (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -195,7 +195,7 @@ heal_model AS (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
|
||||
@ -52,6 +52,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xafc4df6845a4ab948b492800d3d8a25d538a102a2bc07cd01f1cfa097fddcff6'
|
||||
AND contract_address = '0x9295ee1d8c5b022be115a2ad3c30c72e34e7f096'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -60,6 +60,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xa123dc29aebf7d0c3322c8eeb5b999e859f39937950ed31056532713d0de396f'
|
||||
AND contract_address = '0x9295ee1d8c5b022be115a2ad3c30c72e34e7f096'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -53,6 +53,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x884a8def17f0d5bbb3fef53f3136b5320c9b39f75afb8985eeab9ea1153ee56d'
|
||||
AND contract_address = '0xbbbd1bbb4f9b936c3604906d7592a644071de884'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -42,6 +42,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x7e50569d26be643bda7757722291ec66b1be66d8283474ae3fab5a98f878a7a2'
|
||||
AND contract_address = '0x6f015f16de9fc8791b234ef68d486d2bf203fba8'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -89,6 +90,7 @@ native_gas_paid AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x999d431b58761213cf53af96262b67a069cbd963499fd8effd1e21556217b841'
|
||||
AND contract_address = '0x2d5d7d31f671f86c782533cc367f14109a082712'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -52,6 +52,7 @@ WITH base_evt AS (
|
||||
'0x02745032d2aeccdc90310d6cca32cb82c7e149dd',
|
||||
'0xf5c6825015280cdfd0b56903f9f8b5a2233476f5'
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -70,6 +70,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xfc8703fd57380f9dd234a89dce51333782d49c5902f307b02f03e014d18fe471' --CreatedOrder
|
||||
AND contract_address = '0xef4fb24ad0916217251f553c0596f8edc630eb66' --Dln: Source
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -40,6 +40,7 @@ WITH base_evt AS (
|
||||
--PortalV2
|
||||
'0xbf0b5d561b986809924f88099c4ff0e6bcce60c9' --PortalV2
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -14,6 +14,7 @@ WITH base_contracts AS (
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xe35dddd4ea75d7e9b3fe93af4f4e40e778c3da4074c9d93e7c6536f1e803c1eb'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -51,6 +51,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xe35dddd4ea75d7e9b3fe93af4f4e40e778c3da4074c9d93e7c6536f1e803c1eb'
|
||||
AND origin_to_address IS NOT NULL
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -126,6 +126,7 @@ dst_info AS (
|
||||
WHERE
|
||||
contract_address = '0x25ab3efd52e6470681ce037cd546dc60726948d3'
|
||||
AND topics [0] :: STRING = '0x5ce4019f772fda6cb703b26bce3ec3006eb36b73f1d3a0eb441213317d9f5e9d'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -40,6 +40,7 @@ WITH base_evt AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x0d969ae475ff6fcaf0dcfa760d4d8607244e8d95e9bf426f8d5d69f9a3e525af'
|
||||
AND contract_address = '0x1633d66ca91ce4d81f63ea047b7b19beb92df7f3'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform','version'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
tags = ['curated','reorg','heal']
|
||||
) }}
|
||||
|
||||
WITH across AS (
|
||||
@ -33,18 +34,17 @@ WITH across AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__across_fundsdeposited') }}
|
||||
|
||||
{% if is_incremental() and 'across' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'across' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
across_v3 AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
@ -70,11 +70,11 @@ across_v3 AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__across_v3fundsdeposited') }}
|
||||
|
||||
{% if is_incremental() and 'across_v3' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'across_v3' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -106,11 +106,11 @@ allbridge AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__allbridge_sent') }}
|
||||
|
||||
{% if is_incremental() and 'allbridge' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'allbridge' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -142,11 +142,11 @@ axelar AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__axelar_contractcallwithtoken') }}
|
||||
|
||||
{% if is_incremental() and 'axelar' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'axelar' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -178,11 +178,11 @@ celer_cbridge AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__celer_cbridge_send') }}
|
||||
|
||||
{% if is_incremental() and 'celer_cbridge' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'celer_cbridge' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -214,11 +214,11 @@ dln_debridge AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__dln_debridge_createdorder') }}
|
||||
|
||||
{% if is_incremental() and 'dln_debridge' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'dln_debridge' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -250,11 +250,11 @@ eywa AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__eywa_requestsent') }}
|
||||
|
||||
{% if is_incremental() and 'eywa' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'eywa' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -286,11 +286,11 @@ hop AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__hop_transfersent') }}
|
||||
|
||||
{% if is_incremental() and 'hop' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'hop' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -322,11 +322,11 @@ meson AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__meson_transfers') }}
|
||||
|
||||
{% if is_incremental() and 'meson' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'meson' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -358,11 +358,11 @@ multichain AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__multichain_v7_loganyswapout') }}
|
||||
|
||||
{% if is_incremental() and 'multichain' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'multichain' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -394,11 +394,11 @@ stargate AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__stargate_swap') }}
|
||||
|
||||
{% if is_incremental() and 'stargate' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'stargate' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -430,11 +430,11 @@ symbiosis AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__symbiosis_synthesizerequest') }}
|
||||
|
||||
{% if is_incremental() and 'symbiosis' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'symbiosis' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -466,11 +466,11 @@ synapse_tb AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__synapse_token_bridge') }}
|
||||
|
||||
{% if is_incremental() and 'synapse_tb' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'synapse_tb' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -502,11 +502,11 @@ synapse_tbs AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__synapse_tokenbridgeandswap') }}
|
||||
|
||||
{% if is_incremental() and 'synapse_tbs' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'synapse_tbs' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -538,11 +538,11 @@ wormhole AS (
|
||||
FROM
|
||||
{{ ref('silver_bridge__wormhole_transfers') }}
|
||||
|
||||
{% if is_incremental() and 'wormhole' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'wormhole' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
@ -624,7 +624,7 @@ all_protocols AS (
|
||||
FROM
|
||||
wormhole
|
||||
),
|
||||
FINAL AS (
|
||||
complete_bridge_activity AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
@ -680,7 +680,7 @@ FINAL AS (
|
||||
2
|
||||
)
|
||||
ELSE NULL
|
||||
END AS amount_usd_unadj,
|
||||
END AS amount_usd,
|
||||
_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
@ -705,6 +705,183 @@ FINAL AS (
|
||||
) = 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,
|
||||
_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
|
||||
)
|
||||
),
|
||||
{% 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,
|
||||
_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
@ -728,10 +905,7 @@ SELECT
|
||||
token_decimals,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN amount_usd_unadj < 1e+15 THEN amount_usd_unadj
|
||||
ELSE NULL
|
||||
END AS amount_usd,
|
||||
amount_usd,
|
||||
_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
@ -742,7 +916,7 @@ SELECT
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL
|
||||
WHERE destination_chain <> 'polygon'
|
||||
qualify (ROW_NUMBER() over (PARTITION BY _id
|
||||
WHERE
|
||||
destination_chain <> 'polygon' qualify (ROW_NUMBER() over (PARTITION BY _id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
|
||||
@ -20,7 +20,8 @@ WITH base_contracts AS (
|
||||
WHERE
|
||||
from_address = LOWER('0x808d7c71ad2ba3FA531b068a2417C63106BC0949')
|
||||
AND TYPE ILIKE 'create%'
|
||||
AND tx_status ILIKE 'success'
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND trace_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -66,6 +66,7 @@ base_evt AS (
|
||||
ON d.contract_address = p.pool_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x34660fc8af304464529f48a778e03d03e4d34bcd5f9b6f0cfbf3cd238c642f7f'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -44,6 +44,7 @@ WITH base_evt AS (
|
||||
'0xb8f275fbf7a959f4bce59999a2ef122a099e81a8',
|
||||
'0x3338be49a5f60e2593337919f9ad7098e9a7dd7e'
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -49,6 +49,7 @@ WITH base_evt AS (
|
||||
'0x7103a324f423b8a4d4cc1c4f2d5b374af4f0bab5'
|
||||
)
|
||||
AND origin_to_address IS NOT NULL
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -53,6 +53,7 @@ WITH base_evt AS (
|
||||
'0x8f5bbb2bb8c2ee94639e55d5f41de9b4839c1280',
|
||||
'0x0efc29e196da2e81afe96edd041bedcdf9e74893'
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -31,6 +31,7 @@ WITH pools_registered AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x3c13bc30b8e878c53fd2a36b679409c073afd75950be43d8858768e956fbc20e' --PoolRegistered
|
||||
AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -72,6 +73,7 @@ tokens_registered AS (
|
||||
FROM
|
||||
pools_registered
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
),
|
||||
function_sigs AS (
|
||||
SELECT
|
||||
|
||||
@ -57,6 +57,7 @@ swaps_base AS (
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b'
|
||||
AND contract_address = '0xba12222222228d8ba445958a75a0704d566bf2c8'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -33,7 +33,8 @@ WITH contract_deployments AS (
|
||||
'0xe5de15a9c9bbedb4f5ec13b131e61245f2983a69'
|
||||
)
|
||||
AND TYPE ILIKE 'create%'
|
||||
AND tx_status ILIKE 'success'
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND trace_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -69,6 +69,7 @@ curve_base AS (
|
||||
'0xb2e76ae99761dc136e598d4a629bb347eccb9532a5f8bbd72e18467c3c34cc98',
|
||||
'0xd013ca23e77a65003c2c659c5442c00c805371b7fc1ebd4c206c41d1536bd90b'
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -116,6 +117,7 @@ token_transfers AS (
|
||||
curve_base
|
||||
)
|
||||
AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) <> '0x0000000000000000000000000000000000000000'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -24,6 +24,7 @@ WITH pool_events AS (
|
||||
WHERE
|
||||
contract_address = '0x357c5e9cfa8b834edcef7c7aabd8f9db09119d11' --DODOZoo
|
||||
AND topics [0] :: STRING = '0x5c428a2e12ecaa744a080b25b4cda8b86359c82d726575d7d747e07708071f93' --DODOBirth
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -64,6 +64,7 @@ sell_base_token AS (
|
||||
FROM
|
||||
proxies
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -117,6 +118,7 @@ buy_base_token AS (
|
||||
FROM
|
||||
proxies
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -39,6 +39,7 @@ WITH pools AS (
|
||||
--NewDSP
|
||||
'0xaf5c5f12a80fc937520df6fcaed66262a4cc775e0f3fceaf7a7cfe476d9a751d' --NewDVM
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -89,6 +89,7 @@ swaps_base AS (
|
||||
FROM
|
||||
proxies
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -31,6 +31,7 @@ WITH pool_creation AS (
|
||||
'0x54f454d747e037da288db568d4121117eab34e79' --v2 factory
|
||||
)
|
||||
AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --pairCreated
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -59,6 +59,7 @@ swaps_base AS (
|
||||
ON l.contract_address = pool_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' --Swap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -24,7 +24,8 @@ WITH contract_deployments AS (
|
||||
'0x9817a71ca8e309d654ee7e1999577bce6e6fd9ac'
|
||||
)
|
||||
AND TYPE ILIKE 'create%'
|
||||
AND tx_status ILIKE 'success'
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND trace_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -67,6 +67,7 @@ router_swaps_base AS (
|
||||
ON l.contract_address = p.pool_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0xb709ddcc6550418e9b89df1f4938071eeaa3f6376309904c77e15d46b16066f5' --swap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -131,6 +132,7 @@ swaps_base AS (
|
||||
ON l.contract_address = p.pool_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0x8cf3dec1929508e5677d7db003124e74802bfba7250a572205a9986d86ca9f1e' --swap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -21,6 +21,7 @@ WITH contract_deployments AS (
|
||||
WHERE
|
||||
contract_address = '0xde828fdc3f497f16416d1bb645261c7c6a62dab5'
|
||||
AND topics [0] :: STRING = '0xdbd2a1ea6808362e6adbec4db4969cbc11e3b0b28fb6c74cb342defaaf1daada'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -51,6 +51,7 @@ swaps AS (
|
||||
ON l.contract_address = p.pool_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0x34f57786fb01682fb4eec88d340387ef01a168fe345ea5b76f709d4e560c10eb' --Trade
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -34,6 +34,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
contract_address = LOWER('0x5F1fe642060B5B9658C15721Ea22E982643c095c') --dynamic fee factory
|
||||
AND topics [0] :: STRING = '0xfc574402c445e75f2b79b67884ff9c662244dce454c5ae68935fcd0bebb7c8ff' --created pool
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -64,6 +64,7 @@ swaps_base AS (
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0x606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c2499' --Dynamic Swap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -39,6 +39,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
contract_address = LOWER('0x1c758aF0688502e49140230F6b0EBd376d429be5') --static pool factory
|
||||
AND topics [0] :: STRING = '0xb6bce363b712c921bead4bcc977289440eb6172eb89e258e3a25bd49ca806de6' --create pool
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -64,6 +64,7 @@ swaps_base AS (
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0x606ecd02b3e3b4778f8e97b2e03351de14224efaa5fa64e62200afc9395c2499' -- static swap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -30,6 +30,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
contract_address = '0x5f1dddbf348ac2fbe22a163e30f99f9ece3dd50a' --Elastic Pool Deployer
|
||||
AND topics [0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' --Create pool
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -77,6 +77,7 @@ swaps_base AS (
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' -- elastic swap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -27,6 +27,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
contract_address = LOWER('0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32')
|
||||
AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -25,6 +25,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
topics [0] = '0x91ccaa7a278130b65168c3a0c8d3bcae84cf5e43704342bd3ec0b59e59c036db'
|
||||
AND contract_address = LOWER('0x411b0fAcC3489691f28ad58c47006AF5E3Ab3A28')
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
contract_address = LOWER('0xc35DADB65012eC5796536bD9864eD8773aBc74C4')
|
||||
AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -27,6 +27,7 @@ WITH pool_creation AS (
|
||||
WHERE
|
||||
contract_address = LOWER('0x9e5A52f57b3038F1B8EeE45F28b3C1967e22799C')
|
||||
AND topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -32,6 +32,7 @@ WITH created_pools AS (
|
||||
WHERE
|
||||
topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118'
|
||||
AND contract_address = '0x1f98431c8ad98523631ae4a59f267346ea31f984'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -58,6 +59,7 @@ initial_info AS (
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -63,6 +63,7 @@ WITH router_swaps_base AS (
|
||||
'0x817eb46d60762442da3d931ff51a30334ca39b74' --v2
|
||||
)
|
||||
AND topics [0] :: STRING = '0x27c98e911efdd224f4002f6cd831c3ad0d2759ee176f9ee8466d95826af22a1c' --WooRouterSwap
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
@ -133,6 +134,7 @@ swaps_base AS (
|
||||
FROM
|
||||
router_swaps_base
|
||||
)
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
@ -30,19 +31,19 @@ WITH aave AS (
|
||||
FROM
|
||||
{{ ref('silver__aave_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -63,23 +64,21 @@ SELECT
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_borrows') }}
|
||||
A
|
||||
{{ ref('silver__comp_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
),
|
||||
borrow_union as (
|
||||
borrow_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -90,7 +89,7 @@ borrow_union as (
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
FINAL AS (
|
||||
complete_lending_borrows AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -127,8 +126,126 @@ FINAL AS (
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON b.token_address = C.contract_address
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
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
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._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 = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_borrows
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
@ -30,17 +31,17 @@ WITH aave AS (
|
||||
FROM
|
||||
{{ ref('silver__aave_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -63,17 +64,17 @@ SELECT
|
||||
FROM
|
||||
{{ ref('silver__comp_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
deposit_union as (
|
||||
deposit_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -84,7 +85,7 @@ deposit_union as (
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
FINAL AS (
|
||||
complete_lending_deposits AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -122,8 +123,126 @@ FINAL AS (
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON A.token_address = C.contract_address
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
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
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._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 = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_deposits
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
@ -33,24 +34,23 @@ WITH aave AS (
|
||||
FROM
|
||||
{{ ref('silver__aave_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flashloan_union as (
|
||||
flashloan_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
),
|
||||
|
||||
FINAL AS (
|
||||
complete_lending_flashloans AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -65,7 +65,7 @@ FINAL AS (
|
||||
initiator_address AS initiator,
|
||||
target_address AS target,
|
||||
f.token_address AS flashloan_token,
|
||||
token_symbol AS flashloan_token_symbol,
|
||||
f.symbol AS flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
@ -91,8 +91,179 @@ FINAL AS (
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON f.token_address = C.contract_address
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
initiator,
|
||||
target,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
flashloan_amount * p.price,
|
||||
2
|
||||
) AS flashloan_amount_usd_heal,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
ROUND(
|
||||
premium_amount * p.price,
|
||||
2
|
||||
) AS premium_amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.flashloan_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.flashloan_amount_usd IS NULL
|
||||
AND t1._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 = t1.flashloan_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t2.block_number,
|
||||
'-',
|
||||
t2.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t2
|
||||
WHERE
|
||||
t2.premium_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.flashloan_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t2.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_flashloans
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -33,17 +35,17 @@ WITH aave AS (
|
||||
FROM
|
||||
{{ ref('silver__aave_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -71,17 +73,17 @@ comp as (
|
||||
{{ ref('silver__comp_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union as (
|
||||
liquidation_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -92,41 +94,7 @@ liquidation_union as (
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
|
||||
contracts AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__contracts') }} C
|
||||
WHERE
|
||||
C.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(collateral_asset) AS asset
|
||||
FROM
|
||||
liquidation_union
|
||||
)
|
||||
),
|
||||
prices AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
WHERE
|
||||
token_address IN (
|
||||
SELECT
|
||||
DISTINCT(collateral_asset) AS asset
|
||||
FROM
|
||||
liquidation_union
|
||||
)
|
||||
AND HOUR > (
|
||||
SELECT
|
||||
MIN(block_timestamp)
|
||||
FROM
|
||||
liquidation_union
|
||||
)
|
||||
),
|
||||
FINAL AS (
|
||||
complete_lending_liquidations AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -165,14 +133,145 @@ FINAL AS (
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
liquidation_union A
|
||||
LEFT JOIN prices p
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON collateral_asset = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN contracts C
|
||||
ON collateral_asset = C.contract_address
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
CASE
|
||||
WHEN platform <> 'Compound V3' THEN ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
)
|
||||
ELSE ROUND(
|
||||
amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd_heal,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
p
|
||||
ON t0.collateral_token = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._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 = t1.collateral_token
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_liquidations
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
@ -30,17 +31,18 @@ WITH aave AS (
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_repayments') }}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -64,17 +66,17 @@ comp as (
|
||||
FROM
|
||||
{{ ref('silver__comp_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
repayments_union as (
|
||||
repayments_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -85,7 +87,7 @@ repayments_union as (
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
FINAL AS (
|
||||
complete_lending_repayments AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -123,8 +125,128 @@ FINAL AS (
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON A.token_address = C.contract_address
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
payer,
|
||||
borrower,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._LOG_ID,
|
||||
t0._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
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
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._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 = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_repayments
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
-- depends_on: {{ ref('silver__complete_token_prices') }}
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
tags = ['reorg','curated','heal']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
@ -30,19 +31,19 @@ WITH aave AS (
|
||||
FROM
|
||||
{{ ref('silver__aave_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
comp AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -64,19 +65,20 @@ comp as (
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_withdraws') }}
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
withdraws_union as (
|
||||
withdraws_union AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -87,8 +89,7 @@ withdraws_union as (
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
|
||||
FINAL AS (
|
||||
complete_lending_withdraws AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -125,8 +126,126 @@ FINAL AS (
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON A.token_address = C.contract_address
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
t0.contract_address,
|
||||
event_name,
|
||||
protocol_market,
|
||||
depositor,
|
||||
t0.token_address,
|
||||
t0.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * p.price,
|
||||
2
|
||||
) AS amount_usd_heal,
|
||||
platform,
|
||||
t0.blockchain,
|
||||
t0._log_id,
|
||||
t0._inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
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
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.amount_usd IS NULL
|
||||
AND t1._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 = t1.token_address
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t1.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lending_withdraws
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
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 %}
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
|
||||
@ -55,6 +55,7 @@ borrow AS (
|
||||
ON asset = C.compound_market_address
|
||||
WHERE
|
||||
topics [0] = '0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb' --withdrawl
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
|
||||
@ -54,6 +54,7 @@ supply AS (
|
||||
ON asset = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xfa56f7b24f17183d81894d3ac2ee654e3c26388d17a28dbd9549b8114304e1f4' --SupplyCollateral
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
|
||||
@ -58,6 +58,7 @@ liquidations AS (
|
||||
ON asset = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x9850ab1af75177e4a9201c65a2cf7976d5d28e40ef63494b44366f86b2f9412e' --AbsorbCollateral
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
|
||||
@ -58,6 +58,7 @@ repayments AS (
|
||||
ON contract_address = C.compound_market_address
|
||||
WHERE
|
||||
topics [0] = '0xd1cf3d156d5f8f0d50f6c122ed609cec09d35c9b9fb3fff6ea0959134dae424e' --Supply
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
|
||||
@ -53,6 +53,7 @@ withdraw AS (
|
||||
ON token_address = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xd6d480d5b3068db003533b170d67561494d72e3bf9fa40a266471351ebba9e16' --WithdrawCollateral
|
||||
AND tx_status = 'SUCCESS'
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user