mirror of
https://github.com/FlipsideCrypto/aptos-models.git
synced 2026-02-06 16:06:53 +00:00
Merge pull request #81 from FlipsideCrypto/fix/fungible_deletion_metadata
delete stores logic
This commit is contained in:
commit
eaf0afb8ac
@ -7,13 +7,63 @@
|
||||
tags = ['core', 'full_test']
|
||||
) }}
|
||||
|
||||
WITH changes_source AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
address AS store_address,
|
||||
change_data :metadata :inner :: STRING AS metadata_address
|
||||
FROM
|
||||
{{ ref('silver__changes') }}
|
||||
WHERE
|
||||
change_module = 'fungible_asset'
|
||||
AND change_resource = 'FungibleStore'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
-- Capture temporary fungible stores from deletion events
|
||||
deletion_events_source AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
event_data :store :: STRING AS store_address,
|
||||
event_data :metadata :: STRING AS metadata_address
|
||||
FROM
|
||||
{{ ref('silver__events') }}
|
||||
WHERE
|
||||
event_address = '0x1'
|
||||
AND event_module = 'fungible_asset'
|
||||
AND event_resource = 'FungibleStoreDeletion'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
combined AS (
|
||||
SELECT * FROM changes_source
|
||||
UNION ALL
|
||||
SELECT * FROM deletion_events_source
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_timestamp AS block_timestamp_first,
|
||||
block_number AS block_number_first,
|
||||
address AS store_address,
|
||||
change_data :metadata :inner :: STRING AS metadata_address,
|
||||
store_address,
|
||||
metadata_address,
|
||||
CASE
|
||||
WHEN change_data :metadata :inner :: STRING = '0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b' THEN TRUE
|
||||
WHEN metadata_address = '0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b' THEN TRUE
|
||||
ELSE FALSE
|
||||
END AS is_usdt,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
@ -23,22 +73,9 @@ SELECT
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('silver__changes') }}
|
||||
WHERE
|
||||
change_module = 'fungible_asset'
|
||||
AND change_resource = 'FungibleStore'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
combined
|
||||
qualify ROW_NUMBER() over (
|
||||
PARTITION BY address
|
||||
PARTITION BY store_address
|
||||
ORDER BY
|
||||
block_number
|
||||
) = 1
|
||||
|
||||
@ -7,14 +7,72 @@
|
||||
tags = ['core','full_test']
|
||||
) }}
|
||||
|
||||
WITH changes_source AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
version,
|
||||
tx_hash,
|
||||
change_index,
|
||||
address AS store_address,
|
||||
change_data :owner :: STRING AS owner_address
|
||||
FROM
|
||||
{{ ref('silver__changes') }}
|
||||
WHERE
|
||||
change_address = '0x1'
|
||||
AND change_module = 'object'
|
||||
AND change_resource = 'ObjectCore'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
-- Capture temporary fungible store owners from deletion events
|
||||
-- Use negative indices to avoid collision with change_index values
|
||||
deletion_events_source AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
version,
|
||||
tx_hash,
|
||||
-1 * (event_index + 1) AS change_index,
|
||||
event_data :store :: STRING AS store_address,
|
||||
event_data :owner :: STRING AS owner_address
|
||||
FROM
|
||||
{{ ref('silver__events') }}
|
||||
WHERE
|
||||
event_address = '0x1'
|
||||
AND event_module = 'fungible_asset'
|
||||
AND event_resource = 'FungibleStoreDeletion'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
combined AS (
|
||||
SELECT * FROM changes_source
|
||||
UNION ALL
|
||||
SELECT * FROM deletion_events_source
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
version,
|
||||
tx_hash,
|
||||
change_index,
|
||||
address AS store_address,
|
||||
change_data :owner :: STRING AS owner_address,
|
||||
store_address,
|
||||
owner_address,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','change_index']
|
||||
) }} AS fungiblestore_owners_id,
|
||||
@ -22,17 +80,4 @@ SELECT
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('silver__changes') }}
|
||||
WHERE
|
||||
change_address = '0x1'
|
||||
AND change_module = 'object'
|
||||
AND change_resource = 'ObjectCore'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
combined
|
||||
|
||||
Loading…
Reference in New Issue
Block a user