Skip to content

Commit

Permalink
AN-4705/prices-v2 (#269)
Browse files Browse the repository at this point in the history
* prices v2 changes

* transfers

* bronze ref

* source column

* remove id

* yml

* revert id

* modified and id column

* native and provider tables

* lower

* new names

* overview docs

* docs

* id names

* deprecation notice

* yml tests

* docs

* ez refs

* alias

* docs

* update for new names and docs

* deprecation note

* addr desc
  • Loading branch information
drethereum authored May 1, 2024
1 parent 14088c4 commit 010b62b
Show file tree
Hide file tree
Showing 62 changed files with 963 additions and 138 deletions.
26 changes: 26 additions & 0 deletions models/bronze/prices/bronze__complete_native_asset_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{ config (
materialized = 'view'
) }}

SELECT
asset_id,
symbol,
NAME,
decimals,
blockchain,
is_deprecated,
provider,
source,
_inserted_timestamp,
inserted_timestamp,
modified_timestamp,
complete_native_asset_metadata_id,
_invocation_id
FROM
{{ source(
'silver_crosschain',
'complete_native_asset_metadata'
) }}
WHERE
blockchain = 'ethereum'
AND symbol = 'ETH'
29 changes: 29 additions & 0 deletions models/bronze/prices/bronze__complete_native_prices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{ config (
materialized = 'view'
) }}

SELECT
HOUR,
asset_id,
symbol,
NAME,
decimals,
price,
blockchain,
is_imputed,
is_deprecated,
provider,
source,
_inserted_timestamp,
inserted_timestamp,
modified_timestamp,
complete_native_prices_id,
_invocation_id
FROM
{{ source(
'silver_crosschain',
'complete_native_prices'
) }}
WHERE
blockchain = 'ethereum'
AND symbol = 'ETH'
29 changes: 29 additions & 0 deletions models/bronze/prices/bronze__complete_provider_asset_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{ config (
materialized = 'view'
) }}

SELECT
asset_id,
token_address,
NAME,
symbol,
platform,
platform_id,
provider,
source,
_inserted_timestamp,
inserted_timestamp,
modified_timestamp,
complete_provider_asset_metadata_id,
_invocation_id
FROM
{{ source(
'silver_crosschain',
'complete_provider_asset_metadata'
) }}
WHERE
platform IN (
'Optimism',
'optimistic-ethereum'
)
-- platforms specific to Optimism
24 changes: 24 additions & 0 deletions models/bronze/prices/bronze__complete_provider_prices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ config (
materialized = 'view'
) }}

SELECT
asset_id,
recorded_hour,
OPEN,
high,
low,
CLOSE,
provider,
source,
_inserted_timestamp,
inserted_timestamp,
modified_timestamp,
complete_provider_prices_id,
_invocation_id
FROM
{{ source(
'silver_crosschain',
'complete_provider_prices'
) }}
-- prices for all ids
28 changes: 28 additions & 0 deletions models/bronze/prices/bronze__complete_token_asset_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{ config (
materialized = 'view'
) }}

SELECT
token_address,
asset_id,
symbol,
NAME,
decimals,
blockchain,
blockchain_name,
blockchain_id,
is_deprecated,
provider,
source,
_inserted_timestamp,
inserted_timestamp,
modified_timestamp,
complete_token_asset_metadata_id,
_invocation_id
FROM
{{ source(
'silver_crosschain',
'complete_token_asset_metadata'
) }}
WHERE
blockchain = 'optimism'
31 changes: 31 additions & 0 deletions models/bronze/prices/bronze__complete_token_prices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{ config (
materialized = 'view'
) }}

SELECT
HOUR,
token_address,
asset_id,
symbol,
NAME,
decimals,
price,
blockchain,
blockchain_name,
blockchain_id,
is_imputed,
is_deprecated,
provider,
source,
_inserted_timestamp,
inserted_timestamp,
modified_timestamp,
complete_token_prices_id,
_invocation_id
FROM
{{ source(
'silver_crosschain',
'complete_token_prices'
) }}
WHERE
blockchain = 'optimism'
8 changes: 3 additions & 5 deletions models/doc_descriptions/general/__overview__.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ There is more information on how to use dbt docs in the last section of this doc
- [ez_token_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_token_transfers)
- [ez_decoded_event_logs](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_decoded_event_logs)


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

- [ez_prices_hourly](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.price__ez_prices_hourly)

### DeFi Tables (optimism.defi)
- [ez_bridge_activity](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_bridge_activity)
Expand All @@ -57,7 +55,7 @@ There is more information on how to use dbt docs in the last section of this doc
- [ez_lending_repayments](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_repayments)
- [ez_lending_withdraws](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_lending_withdraws)

### Stats Tables (ethereum.stats)
### Stats Tables (optimism.stats)
- [ez_core_metrics_hourly](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.stats__ez_core_metrics_hourly)

**Velodrome**
Expand Down
143 changes: 143 additions & 0 deletions models/doc_descriptions/prices/prices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{% docs prices_dim_asset_metadata_table_doc %}

A comprehensive dimensional table holding asset metadata and other relevant details pertaining to each id, from multiple providers. This data set includes raw, non-transformed data coming directly from the provider APIs and rows are not intended to be unique. As a result, there may be data quality issues persisting in the APIs that flow through to this dimensional model. If you are interested in using a curated data set instead, please utilize ez_asset_metadata.

{% enddocs %}

{% docs prices_ez_asset_metadata_table_doc %}

A convenience table holding prioritized asset metadata and other relevant details pertaining to each token_address and native asset. This data set is highly curated and contains metadata for one unique asset per blockchain.

{% enddocs %}

{% docs prices_fact_prices_ohlc_hourly_table_doc %}

A comprehensive fact table holding id and provider specific open, high, low, close hourly prices, from multiple providers. This data set includes raw, non-transformed data coming directly from the provider APIs and rows are not intended to be unique. As a result, there may be data quality issues persisting in the APIs that flow through to this fact based model. If you are interested in using a curated data set instead, please utilize ez_prices_hourly.

{% enddocs %}

{% docs prices_ez_prices_hourly_table_doc %}

A convenience table for determining token prices by address and blockchain, and native asset prices by symbol and blockchain. This data set is highly curated and contains metadata for one price per hour per unique asset and blockchain.

{% enddocs %}

{% docs prices_provider %}

The provider or source of the data.

{% enddocs %}

{% docs prices_asset_id %}

The unique identifier representing the asset.

{% enddocs %}

{% docs prices_name %}

The name of asset.

{% enddocs %}

{% docs prices_symbol %}

The symbol of asset.

{% enddocs %}

{% docs prices_token_address %}

The specific address representing the asset on a specific platform. This will be NULL if referring to a native asset.

{% enddocs %}

{% docs prices_token_address_evm %}

The specific address representing the asset on a specific platform. This will be NULL if referring to a native asset. The case (upper / lower) may or may not be specified within the `dim_asset_metadata` table, as this column is raw and not transformed, coming directly from the provider APIs. However, in the `ez_` views, it will be lowercase by default for all EVMs.

{% enddocs %}

{% docs prices_blockchain %}

The Blockchain, Network, or Platform for this asset.

{% enddocs %}

{% docs prices_blockchain_id %}

The unique identifier of the Blockchain, Network, or Platform for this asset.

{% enddocs %}

{% docs prices_decimals %}

The number of decimals for the asset. May be NULL.

{% enddocs %}

{% docs prices_is_native %}

A flag indicating assets native to the respective blockchain.

{% enddocs %}

{% docs prices_is_deprecated %}

A flag indicating if the asset is deprecated or no longer supported by the provider.

{% enddocs %}

{% docs prices_id_deprecation %}

Deprecating soon! Please use the `asset_id` column instead.

{% enddocs %}

{% docs prices_decimals_deprecation %}

Deprecating soon! Please use the decimals column in `ez_asset_metadata` or join in `dim_contracts` instead.

{% enddocs %}

{% docs prices_hour %}

Hour that the price was recorded at.

{% enddocs %}

{% docs prices_price %}

Closing price of the recorded hour in USD.

{% enddocs %}

{% docs prices_is_imputed %}

A flag indicating if the price was imputed, or derived, from the last arriving record. This is generally used for tokens with low-liquidity or inconsistent reporting.

{% enddocs %}

{% docs prices_open %}

Opening price of the recorded hour in USD.

{% enddocs %}

{% docs prices_high %}

Highest price of the recorded hour in USD

{% enddocs %}

{% docs prices_low %}

Lowest price of the recorded hour in USD

{% enddocs %}

{% docs prices_close %}

Closing price of the recorded hour in USD

{% enddocs %}
36 changes: 17 additions & 19 deletions models/gold/price/price__dim_asset_metadata.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@

SELECT
token_address,
id,
symbol,
NAME,
decimals,
asset_id AS id, -- id column pending deprecation
asset_id,
A.symbol,
A.name,
C.decimals, -- decimals column pending deprecation
platform AS blockchain,
platform_id AS blockchain_id,
provider,
COALESCE (
asset_metadata_all_providers_id,
{{ dbt_utils.generate_surrogate_key(
['token_address','symbol','id','provider']
) }}
) AS dim_asset_metadata_id,
COALESCE(
inserted_timestamp,
'2000-01-01'
) AS inserted_timestamp,
COALESCE(
modified_timestamp,
'2000-01-01'
) AS modified_timestamp
A.inserted_timestamp,
A.modified_timestamp,
A.complete_provider_asset_metadata_id AS dim_asset_metadata_id
FROM
{{ ref('silver__asset_metadata_all_providers') }}
{{ ref('silver__complete_provider_asset_metadata') }} A
LEFT JOIN {{ ref('core__dim_contracts') }} C --remove this join alongside decimal column deprecation
ON LOWER(
C.address
) = LOWER(
A.token_address
)
Loading

0 comments on commit 010b62b

Please sign in to comment.