mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 15:51:48 +00:00
* add trades and swaps * revert old swaps model and branch into new * swaps v2 still some bugs * dup token0 issue * swaps2 * final * tweak * del todo * incr
65 lines
965 B
SQL
65 lines
965 B
SQL
{{ config(
|
|
materialized = 'incremental',
|
|
cluster_by = ['_inserted_timestamp::DATE'],
|
|
unique_key = "CONCAT_WS('-', tx_id, event_index)",
|
|
incremental_strategy = 'delete+insert'
|
|
) }}
|
|
|
|
WITH swap_contracts AS (
|
|
|
|
SELECT
|
|
*
|
|
FROM
|
|
{{ ref('silver__contract_labels') }}
|
|
WHERE
|
|
contract_name LIKE '%SwapPair%'
|
|
),
|
|
swaps_txs AS (
|
|
SELECT
|
|
*
|
|
FROM
|
|
{{ ref('silver__events_final') }}
|
|
WHERE
|
|
event_contract IN (
|
|
SELECT
|
|
event_contract
|
|
FROM
|
|
swap_contracts
|
|
)
|
|
|
|
{% if is_incremental() %}
|
|
AND _inserted_timestamp >= (
|
|
SELECT
|
|
MAX(_inserted_timestamp)
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
{% endif %}
|
|
),
|
|
swap_events AS (
|
|
SELECT
|
|
*
|
|
FROM
|
|
{{ ref('silver__events_final') }}
|
|
WHERE
|
|
tx_id IN (
|
|
SELECT
|
|
tx_id
|
|
FROM
|
|
swaps_txs
|
|
)
|
|
|
|
{% if is_incremental() %}
|
|
AND _inserted_timestamp >= (
|
|
SELECT
|
|
MAX(_inserted_timestamp)
|
|
FROM
|
|
{{ this }}
|
|
)
|
|
{% endif %}
|
|
)
|
|
SELECT
|
|
*
|
|
FROM
|
|
swap_events
|