Skip to content

Commit

Permalink
AN-3746/schema-reorg-v2 (#76)
Browse files Browse the repository at this point in the history
* all re-org changes

* gnosis final updates

* add decimals

* silver priority fix
  • Loading branch information
mattromano authored Aug 31, 2023
1 parent 099f5a9 commit 5d11f40
Show file tree
Hide file tree
Showing 27 changed files with 329 additions and 57 deletions.
2 changes: 1 addition & 1 deletion models/bronze/labels/bronze__labels.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SELECT
FROM
{{ source(
'crosschain',
'address_labels'
'dim_labels'
) }}
WHERE
blockchain = 'gnosis'
Expand Down
19 changes: 19 additions & 0 deletions models/bronze/prices/bronze__asset_metadata_all_providers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{ config (
materialized = 'view'
) }}

SELECT
token_address,
id,
symbol,
blockchain,
provider,
_unique_key,
_inserted_timestamp
FROM
{{ source(
'crosschain_silver',
'asset_metadata_all_providers'
) }}
WHERE
blockchain = 'gnosis'
20 changes: 20 additions & 0 deletions models/bronze/prices/bronze__hourly_prices_all_providers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ config (
materialized = 'view'
) }}

SELECT
HOUR,
token_address,
blockchain,
provider,
price,
is_imputed,
_inserted_timestamp,
_unique_key
FROM
{{ source(
'crosschain_silver',
'token_prices_all_providers_hourly'
) }}
WHERE
blockchain = 'gnosis'
6 changes: 6 additions & 0 deletions models/doc_descriptions/general/__overview__.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ There is more information on how to use dbt docs in the last section of this doc
- [ez_dex_swaps](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.defi__ez_dex_swaps)
- [dim_dex_liquidity_pools](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.defi__dim_dex_liquidity_pools)

### Price Tables (gnosis.price)
- [fact_hourly_token_prices](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.price__fact_hourly_token_prices)
- [ez_hourly_token_prices](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.price__ez_hourly_token_prices)
- [dim_asset_metadata](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.price__dim_asset_metadata)
- [ez_asset_metadata](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.price__ez_asset_metadata)

### NFT Tables (gnosis.nft) ###
- [ez_nft_transfers](https://flipsidecrypto.github.io/gnosis-models/#!/model/model.gnosis_models.nft__ez_nft_transfers)

Expand Down
2 changes: 1 addition & 1 deletion models/gold/core/core__ez_token_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SELECT
FROM
{{ ref('core__fact_token_transfers') }}
t
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
p
ON t.contract_address = p.token_address
AND DATE_TRUNC(
Expand Down
2 changes: 1 addition & 1 deletion models/gold/core/core__ez_xdai_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ SELECT
trace_index
FROM
xdai_base A
LEFT JOIN {{ ref('silver__prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
ON DATE_TRUNC(
'hour',
A.block_timestamp
Expand Down
9 changes: 2 additions & 7 deletions models/gold/core/core__fact_hourly_token_prices.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
) }}

SELECT
HOUR,
token_address,
symbol,
decimals,
price,
is_imputed
*
FROM
{{ ref('silver__prices') }}
{{ ref('price__ez_hourly_token_prices') }}
2 changes: 1 addition & 1 deletion models/gold/core/core__fact_hourly_token_prices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
models:

- name: core__fact_hourly_token_prices
description: 'This table contains the hourly USD prices for tokens on the Gnosis blockchain.'
description: Deprecating soon! This is a notice that we're replacing this table with `price__ez_hourly_token_prices`. Please migrate queries to the new table by 9/14/23. There will be no column changes or any other changes of any kind.

columns:
- name: HOUR
Expand Down
15 changes: 15 additions & 0 deletions models/gold/prices/price__dim_asset_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true }
) }}

SELECT
token_address,
id,
symbol,
NAME,
decimals,
provider
FROM
{{ ref('silver__asset_metadata_all_providers') }}
25 changes: 25 additions & 0 deletions models/gold/prices/price__dim_asset_metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2
models:
- name: price__dim_asset_metadata
description: A comprehensive dimensional table holding all provider asset metadata and other relevant details pertaining to each token_address.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- PROVIDER
- ID
- TOKEN_ADDRESS
- SYMBOL

columns:
- name: PROVIDER
description: The provider or source of the data.
- name: ID
description: The unique identifier representing the asset.
- name: NAME
description: The name of asset.
- name: SYMBOL
description: The symbol of asset.
- name: TOKEN_ADDRESS
description: The specific address representing the asset in a specific platform.
- name: DECIMALS
description: The number of decimal places the token needs adjusted where token values exist.
14 changes: 14 additions & 0 deletions models/gold/prices/price__ez_asset_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true }
) }}

SELECT
token_address,
id,
symbol,
NAME,
decimals
FROM
{{ ref('silver__asset_metadata_priority') }}
20 changes: 20 additions & 0 deletions models/gold/prices/price__ez_asset_metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
models:
- name: price__ez_asset_metadata
description: A convenience table holding prioritized asset metadata and other relevant details pertaining to each token_address.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TOKEN_ADDRESS

columns:
- name: ID
description: The unique identifier representing the asset.
- name: NAME
description: The name of asset.
- name: SYMBOL
description: The symbol of asset.
- name: TOKEN_ADDRESS
description: The specific address representing the asset in a specific platform.
- name: DECIMALS
description: The number of decimal places the token needs adjusted where token values exist.
15 changes: 15 additions & 0 deletions models/gold/prices/price__ez_hourly_token_prices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true }
) }}

SELECT
HOUR,
token_address,
symbol,
decimals,
price,
is_imputed
FROM
{{ ref('silver__hourly_prices_priority') }}
23 changes: 23 additions & 0 deletions models/gold/prices/price__ez_hourly_token_prices.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2
models:
- name: price__ez_hourly_token_prices
description: A convenience table for determining token prices by address.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- HOUR
- TOKEN_ADDRESS

columns:
- name: HOUR
description: Hour that the price was recorded at
- name: TOKEN_ADDRESS
description: Address of the token
- name: SYMBOL
description: Symbol of the token
- name: DECIMALS
description: The number of decimals for token contract
- name: PRICE
description: Closing price of the recorded hour in USD
- name: IS_IMPUTED
description: Whether the price was imputed from an earlier record (generally used for low trade volume tokens)
14 changes: 14 additions & 0 deletions models/gold/prices/price__fact_hourly_token_prices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true }
) }}

SELECT
HOUR,
token_address,
price,
is_imputed,
provider
FROM
{{ ref('silver__hourly_prices_all_providers') }}
16 changes: 16 additions & 0 deletions models/gold/prices/price__fact_hourly_token_prices.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
models:
- name: price__fact_hourly_token_prices
description: A comprehensive fact table holding provider specific hourly token prices.

columns:
- name: HOUR
description: Hour that the price was recorded at
- name: TOKEN_ADDRESS
description: Address of the token
- name: PROVIDER
description: Source of the token price.
- name: PRICE
description: Closing price of the recorded hour in USD
- name: IS_IMPUTED
description: Whether the price was imputed from an earlier record (generally used for low trade volume tokens)
35 changes: 0 additions & 35 deletions models/silver/prices/silver__asset_metadata.sql

This file was deleted.

41 changes: 41 additions & 0 deletions models/silver/prices/silver__asset_metadata_all_providers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{ config(
materialized = 'incremental',
unique_key = ['token_address','symbol','id','provider'],
tags = ['non_realtime']
) }}

SELECT
token_address,
id,
COALESCE(
C.token_symbol,
p.symbol
) AS symbol,
token_name AS NAME,
token_decimals AS decimals,
provider,
p._inserted_timestamp
FROM
{{ ref('bronze__asset_metadata_all_providers') }}
p
LEFT JOIN {{ ref('silver__contracts') }} C
ON LOWER(
C.contract_address
) = p.token_address
WHERE
1 = 1

{% if is_incremental() %}
AND p._inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}

qualify(ROW_NUMBER() over (PARTITION BY token_address, id, COALESCE(C.token_symbol, p.symbol), provider
ORDER BY
p._inserted_timestamp DESC)) = 1
18 changes: 18 additions & 0 deletions models/silver/prices/silver__asset_metadata_all_providers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
models:
- name: silver__asset_metadata_all_providers
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TOKEN_ADDRESS
- SYMBOL
- PROVIDER
- ID

columns:
- name: TOKEN_ADDRESS
tests:
- not_null
- name: PROVIDER
tests:
- not_null
Loading

0 comments on commit 5d11f40

Please sign in to comment.