mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 15:21:50 +00:00
final model
This commit is contained in:
parent
9d2fcce082
commit
dc355efa52
@ -6,9 +6,41 @@
|
||||
tags = ['scheduled_non_core', 'kittypunch', 'dex', 'combined']
|
||||
) }}
|
||||
|
||||
-- Union all working KittyPunch swap models into a single combined model
|
||||
-- depends on: silver__kittypunch_v2_swaps
|
||||
-- depends on: silver__kittypunch_v3_swaps
|
||||
|
||||
WITH combined_swaps AS (
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp,
|
||||
block_height,
|
||||
event_index,
|
||||
swap_contract,
|
||||
sender_address,
|
||||
NULL AS recipient_address,
|
||||
platform,
|
||||
token_in_contract,
|
||||
token_out_contract,
|
||||
token_in_amount,
|
||||
token_out_amount,
|
||||
raw_data,
|
||||
kittypunch_v2_swaps_id AS source_id,
|
||||
'kittypunch_v2_swaps' AS source_table,
|
||||
inserted_timestamp AS source_inserted_timestamp,
|
||||
modified_timestamp AS source_modified_timestamp
|
||||
FROM {{ ref('silver__kittypunch_v2_swaps') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE modified_timestamp > (
|
||||
SELECT COALESCE(MAX(source_modified_timestamp), '2000-01-01'::TIMESTAMP)
|
||||
FROM {{ this }}
|
||||
WHERE source_table = 'kittypunch_v2_swaps'
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
tx_hash AS tx_id,
|
||||
block_timestamp,
|
||||
@ -36,36 +68,6 @@ WHERE modified_timestamp > (
|
||||
WHERE source_table = 'kittypunch_v3_swaps'
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp,
|
||||
block_height,
|
||||
event_index,
|
||||
pool_address AS swap_contract,
|
||||
user_address AS sender_address,
|
||||
NULL AS recipient_address,
|
||||
platform,
|
||||
token0_address AS token_in_contract,
|
||||
token1_address AS token_out_contract,
|
||||
token0_amount AS token_in_amount,
|
||||
token1_amount AS token_out_amount,
|
||||
raw_data,
|
||||
stablekitty_swaps_id AS source_id,
|
||||
'stablekitty_swaps' AS source_table,
|
||||
inserted_timestamp AS source_inserted_timestamp,
|
||||
modified_timestamp AS source_modified_timestamp
|
||||
FROM {{ ref('silver__stablekitty_swaps') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE modified_timestamp > (
|
||||
SELECT COALESCE(MAX(source_modified_timestamp), '2000-01-01'::TIMESTAMP)
|
||||
FROM {{ this }}
|
||||
WHERE source_table = 'stablekitty_swaps'
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
|
||||
@ -57,6 +57,7 @@ parsed_swaps AS (
|
||||
tx_position,
|
||||
event_index,
|
||||
contract_address AS pair_contract,
|
||||
data,
|
||||
TRY_CAST(utils.udf_hex_to_int(SUBSTR(data, 3, 64)) AS NUMBER) AS amount0,
|
||||
TRY_CAST(utils.udf_hex_to_int(SUBSTR(data, 67, 64)) AS NUMBER) AS amount1
|
||||
FROM
|
||||
@ -73,11 +74,12 @@ swap_with_tokens AS (
|
||||
s.tx_position,
|
||||
s.event_index,
|
||||
s.pair_contract,
|
||||
s.data,
|
||||
t.from_address AS sender_address,
|
||||
s.amount0,
|
||||
s.amount1,
|
||||
p.token0_address,
|
||||
p.token1_address,
|
||||
p.token1_address
|
||||
FROM
|
||||
parsed_swaps s
|
||||
INNER JOIN
|
||||
@ -98,6 +100,7 @@ swap_details AS (
|
||||
tx_position,
|
||||
event_index,
|
||||
pair_contract,
|
||||
data,
|
||||
sender_address,
|
||||
token0_address,
|
||||
token1_address,
|
||||
@ -120,7 +123,7 @@ swap_details AS (
|
||||
CASE
|
||||
WHEN amount0 > 0 THEN token1_address
|
||||
ELSE token0_address
|
||||
END AS token_out_contract,
|
||||
END AS token_out_contract
|
||||
FROM
|
||||
swap_with_tokens
|
||||
WHERE
|
||||
@ -153,7 +156,7 @@ FINAL AS (
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
['tx_id', 'event_index']
|
||||
) }} AS kittypunch_v2_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__stablekitty_swaps
|
||||
description: "StableKitty swap transactions with proper filtering to exclude mint/burn operations"
|
||||
columns:
|
||||
- name: stablekitty_swaps_id
|
||||
description: "Primary key for stablekitty swaps"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: tx_id
|
||||
description: "Transaction hash"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: block_timestamp
|
||||
description: "Timestamp of the block containing the swap"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: block_height
|
||||
description: "Block number"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: event_index
|
||||
description: "Index of the swap event within the transaction"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: pool_address
|
||||
description: "Address of the StableKitty pool contract"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: platform
|
||||
description: "Platform identifier (stablekitty)"
|
||||
tests:
|
||||
- not_null
|
||||
- accepted_values:
|
||||
values: ['stablekitty']
|
||||
|
||||
- name: platform_version
|
||||
description: "Platform version (stable)"
|
||||
tests:
|
||||
- not_null
|
||||
- accepted_values:
|
||||
values: ['stable']
|
||||
|
||||
- name: user_address
|
||||
description: "Address that initiated the swap"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token0_address
|
||||
description: "Address of the first token (typically LP token)"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token1_address
|
||||
description: "Address of the second token"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token0_amount
|
||||
description: "Amount of token0 in the swap (raw)"
|
||||
|
||||
- name: token1_amount
|
||||
description: "Amount of token1 in the swap (raw)"
|
||||
|
||||
- name: swap_amount
|
||||
description: "Swap amount from event data (raw)"
|
||||
|
||||
- name: raw_data
|
||||
description: "Raw event data"
|
||||
|
||||
- name: inserted_timestamp
|
||||
description: "Timestamp when record was inserted"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: modified_timestamp
|
||||
description: "Timestamp when record was last modified"
|
||||
tests:
|
||||
- not_null
|
||||
@ -109,6 +109,38 @@ AND _modified_timestamp >= (
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
swaps_from_kittypunch AS (
|
||||
SELECT
|
||||
block_height,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
event_index AS swap_index,
|
||||
swap_contract,
|
||||
platform,
|
||||
sender_address AS trader,
|
||||
token_in_amount,
|
||||
token_in_contract,
|
||||
NULL AS token_in_destination,
|
||||
token_out_amount,
|
||||
token_out_contract,
|
||||
NULL AS token_out_source,
|
||||
source_modified_timestamp AS _modified_timestamp,
|
||||
3 AS _priority
|
||||
FROM
|
||||
{{ ref('silver__kittypunch_swaps_combined') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
source_modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
swaps_union AS (
|
||||
SELECT
|
||||
*
|
||||
@ -124,10 +156,12 @@ swaps_union AS (
|
||||
*
|
||||
FROM
|
||||
swaps
|
||||
) {# Note - curr prices pipeline does not include token address data, making the join difficult and
|
||||
inaccurate.NEW prices models DO have this so will
|
||||
ADD
|
||||
price fields WITH may RELEASE.#}
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
swaps_from_kittypunch
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user