Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP T 16269 broken erc721 balances tables #1525

Merged
merged 6 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions models/balances/ethereum/balances_ethereum_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ models:
blockchain: ethereum
sector: balances
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['balances', 'ethereum', 'erc721', 'day', 'soispoke', 'dot2dotseurat', 'hildobby']
description: >
Expand Down Expand Up @@ -140,7 +140,7 @@ models:
blockchain: ethereum
sector: balances
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['balances', 'ethereum', 'erc721', 'hour', 'soispoke', 'dot2dotseurat', 'hildobby']
description: >
Expand All @@ -160,7 +160,7 @@ models:
blockchain: ethereum
sector: balances
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['balances', 'ethereum', 'erc721', 'latest', 'soispoke', 'dot2dotseurat', 'hildobby']
description: >
Expand All @@ -169,8 +169,8 @@ models:
columns:
- *blockchain
- *last_updated
- *wallet_address
- *token_address
- *wallet_address_erc721
- *token_address_erc721
- *tokenId
- *collection
- *category
Expand All @@ -191,10 +191,10 @@ models:
- *day
- &wallet_address_erc1155
name: wallet_address
description: "Address of the wallet holding this ERC721 token"
description: "Address of the wallet holding this ERC1155 tokens"
- &token_address_erc1155
name: token_address
description: "Contract address for the ERC721 token"
description: "Contract address for the ERC1155 tokens"
- &tokenId_erc1155
name: tokenId
description: "ID of this ERC721 token"
Expand Down Expand Up @@ -239,9 +239,9 @@ models:
columns:
- *blockchain
- *last_updated
- *wallet_address
- *token_address
- *wallet_address_erc1155
- *token_address_erc1155
- *tokenId_erc1155
- *amount_erc1155
- *collection
- *category
- *category
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
token_address,
tokenId,
day,
lead(day, 1, now()) OVER (PARTITION BY token_address, wallet_address ORDER BY day) AS next_day
lead(day, 1, now()) OVER (PARTITION BY token_address, tokenId ORDER BY day) AS next_day
FROM {{ ref('transfers_ethereum_erc721_rolling_day') }})

SELECT distinct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
token_address,
tokenId,
hour,
lead(hour, 1, now()) OVER (PARTITION BY token_address, wallet_address ORDER BY hour) AS next_hour
lead(hour, 1, now()) OVER (PARTITION BY token_address, tokenId ORDER BY hour) AS next_hour
FROM {{ ref('transfers_ethereum_erc721_rolling_hour') }})

SELECT distinct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SELECT distinct
tokenId,
nft_tokens.name as collection,
updated_at
FROM {{ ref('transfers_ethereum_erc721_rolling_hour') }}
FROM {{ ref('transfers_ethereum_erc721_rolling_day') }}
LEFT JOIN {{ ref('tokens_nft') }} nft_tokens ON nft_tokens.contract_address = token_address
AND nft_tokens.blockchain = 'ethereum'
WHERE recency_index = 1
12 changes: 6 additions & 6 deletions models/transfers/ethereum/erc721/transfers_ethereum_erc721.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ config(materialized='view', alias='erc721') }}

with
sent_transfers as (
select 'send' || '-' || evt_tx_hash || '-' || evt_index || '-' || `to` as unique_tx_id,
received_transfers as (
select 'receive' || '-' || evt_tx_hash || '-' || evt_index || '-' || `to` as unique_tx_id,
to as wallet_address,
contract_address as token_address,
evt_block_time,
Expand All @@ -13,8 +13,8 @@ with
)

,
received_transfers as (
select 'receive' || '-' || evt_tx_hash || '-' || evt_index || '-' || `from` as unique_tx_id,
sent_transfers as (
select 'send' || '-' || evt_tx_hash || '-' || evt_index || '-' || `from` as unique_tx_id,
from as wallet_address,
contract_address as token_address,
evt_block_time,
Expand All @@ -25,7 +25,7 @@ with
)

select 'ethereum' as blockchain, wallet_address, token_address, evt_block_time, tokenId, amount, unique_tx_id
from sent_transfers
from received_transfers
union
select 'ethereum' as blockchain, wallet_address, token_address, evt_block_time, tokenId, amount, unique_tx_id
from received_transfers
from sent_transfers
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ config(
alias ='erc721_agg_day',
alias ='erc721_agg_day',
materialized ='incremental',
file_format ='delta',
incremental_strategy='merge',
Expand All @@ -13,12 +13,11 @@ select
wallet_address,
token_address,
tokenId,
unique_tx_id || '-' || wallet_address || '-' || token_address || tokenId as unique_transfer_id
date_trunc('day', evt_block_time) || '-' || token_address || '-' || tokenId as unique_transfer_id
from {{ ref('transfers_ethereum_erc721') }}
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
where date_trunc('day', evt_block_time) > now() - interval 2 days
where evt_block_time >= date_trunc('hour', now() - interval '1 week')
{% endif %}
group by
date_trunc('day', evt_block_time), wallet_address, token_address, tokenId,unique_tx_id
having sum(amount) = 1
group by 1,2,3,4,5
having sum(amount) = 1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ config(
alias ='erc721_agg_hour',
alias ='erc721_agg_hour',
materialized ='incremental',
file_format ='delta',
incremental_strategy='merge',
Expand All @@ -13,12 +13,11 @@ select
wallet_address,
token_address,
tokenId,
unique_tx_id || '-' || wallet_address || '-' || token_address || tokenId as unique_transfer_id
date_trunc('hour', evt_block_time) || '-' || token_address || '-' || tokenId as unique_transfer_id
from {{ ref('transfers_ethereum_erc721') }}
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
where date_trunc('hour', evt_block_time) > now() - interval 2 days
where evt_block_time >= date_trunc('day', now() - interval '1 week')
{% endif %}
group by
date_trunc('hour', evt_block_time), wallet_address, token_address, tokenId,unique_tx_id
having sum(amount) = 1
group by 1,2,3,4,5
having sum(amount) = 1
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
token_address,
tokenId,
current_timestamp() as updated_at,
row_number() over (partition by token_address, tokenId, wallet_address order by day desc) as recency_index
from {{ ref('transfers_ethereum_erc721_agg_day') }}
row_number() over (partition by token_address, tokenId order by day desc) as recency_index
from {{ ref('transfers_ethereum_erc721_agg_day') }}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
token_address,
tokenId,
current_timestamp() as updated_at,
row_number() over (partition by token_address, tokenId, wallet_address order by hour desc) as recency_index
from {{ ref('transfers_ethereum_erc721_agg_hour') }}
row_number() over (partition by token_address, tokenId order by hour desc) as recency_index
from {{ ref('transfers_ethereum_erc721_agg_hour') }}
22 changes: 15 additions & 7 deletions models/transfers/ethereum/transfers_ethereum_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ models:
blockchain: ethereum
sector: transfers
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['transfers', 'ethereum', 'erc721', 'soispoke', 'dot2dotseurat', 'hildobby']
description: "ERC721 Token Transfers on Ethereum. This table is updated every 30 minutes."
Expand All @@ -142,7 +142,7 @@ models:
name: wallet_address
description: "Wallet address of sender or receiver."
- &token_address_erc721
name: token_address_erc721
name: token_address
- name: symbol
description: "ERC721 token symbol"
- *evt_block_time
Expand All @@ -157,7 +157,7 @@ models:
blockchain: ethereum
sector: transfers
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['transfers', 'ethereum', 'erc721', 'agg_hour', 'soispoke', 'dot2dotseurat', 'hildobby']
columns:
Expand All @@ -166,13 +166,17 @@ models:
- *wallet_address_erc721
- *token_address_erc721
- *tokenId
- name: unique_transfer_id
description: "Unique ID, used in order to apply the merge into incremental strategy"
tests:
- unique

- name: transfers_ethereum_erc721_rolling_hour
meta:
blockchain: ethereum
sector: transfers
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['transfers', 'ethereum', 'erc721', 'rolling_hour', 'soispoke', 'dot2dotseurat', 'hildobby']
columns:
Expand All @@ -191,7 +195,7 @@ models:
blockchain: ethereum
sector: transfers
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['transfers', 'ethereum', 'erc721', 'agg_hour', 'soispoke', 'dot2dotseurat', 'hildobby']
columns:
Expand All @@ -200,13 +204,17 @@ models:
- *wallet_address_erc721
- *token_address_erc721
- *tokenId
- name: unique_transfer_id
description: "Unique ID, used in order to apply the merge into incremental strategy"
tests:
- unique

- name: transfers_ethereum_erc721_rolling_day
meta:
blockchain: ethereum
sector: transfers
project: erc721
contibutors: soispoke, dot2dotseurat, hildobby
contibutors: soispoke, dot2dotseurat, hildobby, 0xRob
config:
tags: ['transfers', 'ethereum', 'erc721', 'rolling_day', 'soispoke', 'dot2dotseurat', 'hildobby']
columns:
Expand Down Expand Up @@ -317,4 +325,4 @@ models:
- name: updated_at
description: "UTC timestamp when table was last updated"
- name: recency_index
description: "Index of most recent balance ascending. recency_index=1 is the wallet/contract pair's most recent balance"
description: "Index of most recent balance ascending. recency_index=1 is the wallet/contract pair's most recent balance"
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

select blockchain,
day,
wallet_address,
token_address,
tokenId,
count(*)
from {{ ref('balances_ethereum_erc721_day') }}
where day >= now() - interval '2 days'
group by blockchain, day, wallet_address, token_address, tokenId
group by blockchain, day, token_address, tokenId
having count(*) > 1
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

select blockchain,
hour,
wallet_address,
token_address,
tokenId,
count(*)
from {{ ref('balances_ethereum_erc721_hour') }}
where hour >= now() - interval '2 hours'
group by blockchain, hour, wallet_address, token_address, tokenId
group by blockchain, hour, token_address, tokenId
having count(*) > 1