Skip to content

Commit

Permalink
Balance improvements (duneanalytics#7290)
Browse files Browse the repository at this point in the history
* move safe balance models

* add incremental to balances and use daily prices table
  • Loading branch information
0xRobin authored Dec 13, 2024
1 parent 2d7e97a commit 025892f
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 387 deletions.
12 changes: 8 additions & 4 deletions dbt_macros/shared/balances_incremental_subset_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,18 @@ from(
{% endif %}

) b
left join {{source('prices','usd')}} p
on (token_standard = 'erc20'
left join {{source('prices','usd_daily')}} p
on 1=1
{% if is_incremental() %}
and {{ incremental_predicate('p.day') }}
{% endif %}
and ((token_standard = 'erc20'
and p.blockchain = '{{blockchain}}'
and b.token_address = p.contract_address
and b.day = p.minute)
and b.day = p.day)
or (token_standard = 'native'
and p.blockchain is null
and p.contract_address is null
and p.symbol = (select native_token_symbol from {{source('evms','info')}} where blockchain = '{{blockchain}}')
and b.day = p.minute)
and b.day = p.day))
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
version: 2

models:
- name: safe_arbitrum_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: arbitrum
project: safe
contributors: safeintern
config:
tags: ['safe', 'arbitrum']
description: “Safe addresses balances”

- name: safe_avalanche_c_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: avalanche_c
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'avalanche_c' ]
description: “Safe addresses balances”

- name: safe_base_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: base
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'base' ]
description: “Safe addresses balances”

- name: safe_ethereum_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: ethereum
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'ethereum' ]
description: “Safe addresses balances”

- name: safe_linea_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: linea
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'linea' ]
description: “Safe addresses balances”

- name: safe_optimism_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: optimism
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'optimism' ]
description: “Safe addresses balances”

- name: safe_polygon_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: polygon
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'polygon' ]
description: “Safe addresses balances”

- name: safe_scroll_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: scroll
project: safe
contributors: safeintern
config:
tags: [ 'safe', 'scroll' ]
description: “Safe addresses balances”

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_arbitrum_safes') }}
from {{ source('safe_arbitrum','safes') }}
where blockchain = 'arbitrum'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_avalanche_c_safes') }}
from {{ source('safe_avalanche_c','safes') }}
where blockchain = 'avalanche_c'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_base_safes') }}
from {{ source('safe_base','safes') }}
where blockchain = 'base'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_ethereum_safes') }}
from {{ source('safe_ethereum','safes') }}
where blockchain = 'ethereum'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_linea_safes') }}
from {{ source('safe_linea','safes') }}
where blockchain = 'linea'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_optimism_safes') }}
from {{ source('safe_optimism','safes') }}
where blockchain = 'optimism'
),
balances as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_polygon_safes') }}
from {{ source('safe_polygon','safes') }}
where blockchain = 'polygon'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with safes as (
select
address,
blockchain
from {{ ref('safe_scroll_safes') }}
from {{ source('safe_scroll','safes') }}
where blockchain = 'scroll'
),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,49 +149,3 @@ models:
- &amount_usd
name: amount_usd
description: "USD amount of transferred ETH"

- name: safe_arbitrum_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: arbitrum
project: safe
contributors: safeintern
config:
tags: ['safe', 'arbitrum']
description: “Safe addresses balances”
columns:
- name: day
- name: blockchain
- name: address
- &token_symbol
name: token_symbol
description: "Symbol for the token"
- &token_address
name: token_address
description: "Address for the token"
- &token_standard
name: token_standard
description: "Standard for the token"
- &token_id
name: token_id
description: "ID for the token"
- &balance
name: balance
description: "Balance for the user"
- &balance_usd
name: balance_usd
description: "USD value of balance for the user"
- &last_updated
name: last_updated
description: "UTC timestamp when data was last updated"
- &next_update
name: next_update
description: "UTC timestamp when data is next updated"
- &unique_key_id
name: unique_key_id
description: " unique key"
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ models:
name: value
description: "Value of transaction"
- &gas
name: gas
name: gas
description: "Gas limit set for transaction"
- &execution_gas_used
name: execution_gas_used
Expand Down Expand Up @@ -149,49 +149,3 @@ models:
- &amount_usd
name: amount_usd
description: "USD amount of transferred AVAX"

- name: safe_avalanche_c_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: avalanche_c
project: safe
contributors: safeintern
config:
tags: ['safe', 'avalanche_c']
description: “Safe addresses balances”
columns:
- name: day
- name: blockchain
- name: address
- &token_symbol
name: token_symbol
description: "Symbol for the token"
- &token_address
name: token_address
description: "Address for the token"
- &token_standard
name: token_standard
description: "Standard for the token"
- &token_id
name: token_id
description: "ID for the token"
- &balance
name: balance
description: "Balance for the user"
- &balance_usd
name: balance_usd
description: "USD value of balance for the user"
- &last_updated
name: last_updated
description: "UTC timestamp when data was last updated"
- &next_update
name: next_update
description: "UTC timestamp when data is next updated"
- &unique_key_id
name: unique_key_id
description: "unique key"
Original file line number Diff line number Diff line change
Expand Up @@ -141,49 +141,3 @@ models:
- &output
name: output
description: "Output data"

- name: safe_base_balances
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- day
- address
- token_address
meta:
blockchain: base
project: safe
contributors: safeintern
config:
tags: ['safe', 'base']
description: “Safe addresses balances”
columns:
- name: day
- name: blockchain
- name: address
- &token_symbol
name: token_symbol
description: "Symbol for the token"
- &token_address
name: token_address
description: "Address for the token"
- &token_standard
name: token_standard
description: "Standard for the token"
- &token_id
name: token_id
description: "ID for the token"
- &balance
name: balance
description: "Balance for the user"
- &balance_usd
name: balance_usd
description: "USD value of balance for the user"
- &last_updated
name: last_updated
description: "UTC timestamp when data was last updated"
- &next_update
name: next_update
description: "UTC timestamp when data is next updated"
- &unique_key_id
name: unique_key_id
description: " unique key"
Loading

0 comments on commit 025892f

Please sign in to comment.