diff --git a/models/bronze/prices/bronze__complete_native_asset_metadata.sql b/models/bronze/prices/bronze__complete_native_asset_metadata.sql new file mode 100644 index 0000000..7eafd51 --- /dev/null +++ b/models/bronze/prices/bronze__complete_native_asset_metadata.sql @@ -0,0 +1,25 @@ +{{ 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( + 'crosschain_silver', + 'complete_native_asset_metadata' + ) }} +WHERE + blockchain = 'sei' diff --git a/models/bronze/prices/bronze__complete_provider_asset_metadata.sql b/models/bronze/prices/bronze__complete_provider_asset_metadata.sql new file mode 100644 index 0000000..3b6d50d --- /dev/null +++ b/models/bronze/prices/bronze__complete_provider_asset_metadata.sql @@ -0,0 +1,28 @@ +{{ 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( + 'crosschain_silver', + 'complete_provider_asset_metadata' + ) }} +WHERE + platform IN ( + 'sei-network', + 'sei-v2' + ) diff --git a/models/bronze/prices/bronze__complete_provider_prices.sql b/models/bronze/prices/bronze__complete_provider_prices.sql new file mode 100644 index 0000000..c726661 --- /dev/null +++ b/models/bronze/prices/bronze__complete_provider_prices.sql @@ -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( + 'crosschain_silver', + 'complete_provider_prices' + ) }} + -- prices for all ids diff --git a/models/bronze/prices/bronze__complete_token_asset_metadata.sql b/models/bronze/prices/bronze__complete_token_asset_metadata.sql new file mode 100644 index 0000000..2b0713f --- /dev/null +++ b/models/bronze/prices/bronze__complete_token_asset_metadata.sql @@ -0,0 +1,31 @@ +{{ 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( + 'crosschain_silver', + 'complete_token_asset_metadata' + ) }} +WHERE + blockchain IN ( + 'sei network', + 'sei v2' + ) diff --git a/models/bronze/prices/bronze__complete_token_prices.sql b/models/bronze/prices/bronze__complete_token_prices.sql new file mode 100644 index 0000000..6048303 --- /dev/null +++ b/models/bronze/prices/bronze__complete_token_prices.sql @@ -0,0 +1,34 @@ +{{ 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( + 'crosschain_silver', + 'complete_token_prices' + ) }} +WHERE + blockchain IN ( + 'sei network', + 'sei v2' + ) diff --git a/models/descriptions/__overview__.md b/models/descriptions/__overview__.md index b576fe5..b705b00 100644 --- a/models/descriptions/__overview__.md +++ b/models/descriptions/__overview__.md @@ -20,6 +20,7 @@ There is more information on how to use dbt docs in the last section of this doc ### Core Tables (`SEI`.`CORE`.``) ### Defi Tables (`SEI`.`DEFI`.``) ### Governance Tables (`SEI`.`GOV`.``) +### Pricing Tables (`SEI`.`PRICE`.``) ### Statistics/Analytics Tables (`SEI`.`STATS`.``) ### EVM Tables (`SEI`.`CORE_EVM`.``) @@ -49,6 +50,12 @@ There is more information on how to use dbt docs in the last section of this doc - [fact_dex_swaps](#!/model/model.sei_models.defi__fact_dex_swaps) - [fact_lp_actions](#!/model/model.sei_models.defi__fact_lp_actions) +**Pricing Tables:** +- [dim_asset_metadata](#!/model/model.sei_models.price__dim_asset_metadata) +- [fact_prices_ohlc_hourly](#!/model/model.sei_models.price__fact_prices_ohlc_hourly) +- [ez_asset_metadata](#!/model/model.sei_models.price__ez_asset_metadata) +- [ez_prices_hourly](#!/model/model.sei_models.price__ez_prices_hourly) + **Stats EZ Tables:** - [ez_core_metrics_hourly](#!/model/model.sei_models.ez_core_metrics_hourly) diff --git a/models/descriptions/prices/prices.md b/models/descriptions/prices/prices.md new file mode 100644 index 0000000..60d4e96 --- /dev/null +++ b/models/descriptions/prices/prices.md @@ -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 %} \ No newline at end of file diff --git a/models/gold/price/price__dim_asset_metadata.sql b/models/gold/price/price__dim_asset_metadata.sql new file mode 100644 index 0000000..5f58f76 --- /dev/null +++ b/models/gold/price/price__dim_asset_metadata.sql @@ -0,0 +1,58 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + unique_key = 'dim_asset_metadata_id', + tags = ['core'] +) }} + +SELECT + token_address, + asset_id, + symbol, + NAME, + platform AS blockchain, + platform_id AS blockchain_id, + provider, + inserted_timestamp, + modified_timestamp, + complete_provider_asset_metadata_id AS dim_asset_metadata_id +FROM + {{ ref('silver__complete_provider_asset_metadata') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + modified_timestamp + ) + FROM + {{ this }} + ) +{% endif %} +UNION ALL +SELECT + 'usei' AS token_address, + asset_id, + LOWER(symbol) AS symbol, + NAME, + 'sei-network' AS blockchain, + 'sei-network' AS blockchain_id, + provider, + inserted_timestamp, + modified_timestamp, + complete_native_asset_metadata_id AS dim_asset_metadata_id +FROM + {{ ref('silver__complete_native_asset_metadata') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + modified_timestamp + ) + FROM + {{ this }} + ) +{% endif %} diff --git a/models/gold/price/price__dim_asset_metadata.yml b/models/gold/price/price__dim_asset_metadata.yml new file mode 100644 index 0000000..bbc1254 --- /dev/null +++ b/models/gold/price/price__dim_asset_metadata.yml @@ -0,0 +1,41 @@ +version: 2 +models: + - name: price__dim_asset_metadata + description: '{{ doc("prices_dim_asset_metadata_table_doc") }}' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - ASSET_ID + - TOKEN_ADDRESS + - NAME + - SYMBOL + - BLOCKCHAIN + - BLOCKCHAIN_ID + - PROVIDER + columns: + - name: PROVIDER + description: '{{ doc("prices_provider")}}' + tests: + - not_null + - name: ASSET_ID + description: '{{ doc("prices_asset_id") }}' + tests: + - not_null + - name: NAME + description: '{{ doc("prices_name") }}' + - name: SYMBOL + description: '{{ doc("prices_symbol") }}' + - name: TOKEN_ADDRESS + description: '{{ doc("prices_token_address_evm") }}' + - name: BLOCKCHAIN + description: '{{ doc("prices_blockchain") }}' + - name: BLOCKCHAIN_ID + description: '{{ doc("prices_blockchain_id") }}' + - name: DIM_ASSET_METADATA_ID + description: '{{ doc("pk") }}' + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' + tests: + - not_null \ No newline at end of file diff --git a/models/gold/price/price__ez_asset_metadata.sql b/models/gold/price/price__ez_asset_metadata.sql new file mode 100644 index 0000000..d6b8c67 --- /dev/null +++ b/models/gold/price/price__ez_asset_metadata.sql @@ -0,0 +1,106 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + unique_key = 'ez_asset_metadata_id', + tags = ['core'] +) }} + +WITH base AS ( + + SELECT + token_address, + asset_id, + symbol, + NAME, + decimals, + blockchain, + FALSE AS is_native, + is_deprecated, + inserted_timestamp, + modified_timestamp, + complete_token_asset_metadata_id AS ez_asset_metadata_id + FROM + {{ ref('silver__complete_token_asset_metadata') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + DATEADD( + 'minute', + -90, + modified_timestamp + ) + ) + FROM + {{ this }} + ) +{% endif %} + +qualify(ROW_NUMBER() over (PARTITION BY token_address +ORDER BY + provider, inserted_timestamp DESC) = 1) +UNION ALL +SELECT + 'usei' AS token_address, + asset_id, + symbol, + NAME, + decimals, + blockchain, + TRUE AS is_native, + is_deprecated, + inserted_timestamp, + modified_timestamp, + complete_native_asset_metadata_id AS ez_asset_metadata_id +FROM + {{ ref('silver__complete_native_asset_metadata') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + DATEADD( + 'minute', + -90, + modified_timestamp + ) + ) + FROM + {{ this }} + ) +{% endif %} +) +SELECT + token_address, + asset_id, + COALESCE( + b.symbol, + C.symbol, + A.symbol + ) AS symbol, + COALESCE( + b.token_name, + C.name, + A.name + ) AS NAME, + COALESCE( + b.decimals, + C.decimals, + A.decimals + ) AS decimals, + blockchain, + is_native, + is_deprecated, + A.inserted_timestamp, + A.modified_timestamp, + ez_asset_metadata_id +FROM + base A + LEFT JOIN {{ ref('core__dim_tokens') }} + b + ON A.token_address = b.currency + LEFT JOIN {{ ref('core_evm__dim_contracts') }} C + ON A.token_address = C.address diff --git a/models/gold/price/price__ez_asset_metadata.yml b/models/gold/price/price__ez_asset_metadata.yml new file mode 100644 index 0000000..c20ef33 --- /dev/null +++ b/models/gold/price/price__ez_asset_metadata.yml @@ -0,0 +1,39 @@ +version: 2 +models: + - name: price__ez_asset_metadata + description: '{{ doc("prices_ez_asset_metadata_table_doc") }}' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - TOKEN_ADDRESS + - BLOCKCHAIN + columns: + - name: ASSET_ID + description: '{{ doc("prices_asset_id") }}' + tests: + - not_null + - name: NAME + description: '{{ doc("prices_name") }}' + - name: SYMBOL + description: '{{ doc("prices_symbol") }}' + - name: TOKEN_ADDRESS + description: '{{ doc("prices_token_address_evm") }}' + tests: + - not_null + - name: BLOCKCHAIN + description: '{{ doc("prices_blockchain") }}' + tests: + - not_null + - name: DECIMALS + description: '{{ doc("prices_decimals") }}' + - name: IS_NATIVE + description: '{{ doc("prices_is_native") }}' + - name: IS_DEPRECATED + description: '{{ doc("prices_is_deprecated") }}' + - name: EZ_ASSET_METADATA_ID + description: '{{ doc("pk") }}' + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' + \ No newline at end of file diff --git a/models/gold/price/price__ez_prices_hourly.sql b/models/gold/price/price__ez_prices_hourly.sql new file mode 100644 index 0000000..b819e53 --- /dev/null +++ b/models/gold/price/price__ez_prices_hourly.sql @@ -0,0 +1,90 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + unique_key = 'ez_prices_hourly_id', + cluster_by = ['hour::DATE'], + post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(token_address, symbol, name)", + tags = ['core'] +) }} + +WITH base AS ( + + SELECT + HOUR, + token_address, + price, + blockchain, + FALSE AS is_native, + is_imputed, + is_deprecated, + inserted_timestamp, + modified_timestamp, + complete_token_prices_id AS ez_prices_hourly_id + FROM + {{ ref('silver__complete_token_prices') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + DATEADD( + 'minute', + -90, + modified_timestamp + ) + ) + FROM + {{ this }} + ) +{% endif %} +UNION ALL +SELECT + HOUR, + 'usei' AS token_address, + price, + blockchain, + TRUE AS is_native, + is_imputed, + is_deprecated, + inserted_timestamp, + modified_timestamp, + complete_native_prices_id AS ez_prices_hourly_id +FROM + {{ ref('silver__complete_native_prices') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + DATEADD( + 'minute', + -90, + modified_timestamp + ) + ) + FROM + {{ this }} + ) +{% endif %} +) +SELECT + HOUR, + A.token_address, + b.symbol, + b.name, + b.decimals, + price, + A.blockchain, + A.is_native, + A.is_imputed, + A.is_deprecated, + A.inserted_timestamp, + A.modified_timestamp, + A.ez_prices_hourly_id +FROM + base A + LEFT JOIN {{ ref('price__ez_asset_metadata') }} + b + ON A.token_address = b.token_address diff --git a/models/gold/price/price__ez_prices_hourly.yml b/models/gold/price/price__ez_prices_hourly.yml new file mode 100644 index 0000000..0bf9b4a --- /dev/null +++ b/models/gold/price/price__ez_prices_hourly.yml @@ -0,0 +1,47 @@ +version: 2 +models: + - name: price__ez_prices_hourly + description: '{{ doc("prices_ez_prices_hourly_table_doc") }}' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - HOUR + - TOKEN_ADDRESS + - BLOCKCHAIN + columns: + - name: HOUR + description: '{{ doc("prices_hour")}}' + tests: + - not_null + - name: TOKEN_ADDRESS + description: '{{ doc("prices_token_address_evm") }}' + tests: + - not_null + - name: SYMBOL + description: '{{ doc("prices_symbol") }}' + - name: BLOCKCHAIN + description: '{{ doc("prices_blockchain") }}' + - name: DECIMALS + description: '{{ doc("prices_decimals") }}' + - name: PRICE + description: '{{ doc("prices_price") }}' + tests: + - not_null + - name: IS_NATIVE + description: '{{ doc("prices_is_native") }}' + tests: + - not_null + - name: IS_IMPUTED + description: '{{ doc("prices_is_imputed") }}' + tests: + - not_null + - name: IS_DEPRECATED + description: '{{ doc("prices_is_deprecated") }}' + tests: + - not_null + - name: EZ_PRICES_HOURLY_ID + description: '{{ doc("pk") }}' + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' \ No newline at end of file diff --git a/models/gold/price/price__fact_prices_ohlc_hourly.sql b/models/gold/price/price__fact_prices_ohlc_hourly.sql new file mode 100644 index 0000000..aa39ec8 --- /dev/null +++ b/models/gold/price/price__fact_prices_ohlc_hourly.sql @@ -0,0 +1,33 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + unique_key = 'fact_prices_ohlc_hourly_id', + cluster_by = ['HOUR::DATE','asset_id'], + tags = ['core'] +) }} + +SELECT + asset_id, + recorded_hour AS HOUR, + OPEN, + high, + low, + CLOSE, + provider, + inserted_timestamp, + modified_timestamp, + complete_provider_prices_id AS fact_prices_ohlc_hourly_id +FROM + {{ ref('silver__complete_provider_prices') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX( + modified_timestamp + ) + FROM + {{ this }} + ) +{% endif %} diff --git a/models/gold/price/price__fact_prices_ohlc_hourly.yml b/models/gold/price/price__fact_prices_ohlc_hourly.yml new file mode 100644 index 0000000..a4d3a53 --- /dev/null +++ b/models/gold/price/price__fact_prices_ohlc_hourly.yml @@ -0,0 +1,37 @@ +version: 2 +models: + - name: price__fact_prices_ohlc_hourly + description: '{{ doc("prices_fact_prices_ohlc_hourly_table_doc") }}' + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - HOUR + - ASSET_ID + - PROVIDER + columns: + - name: HOUR + description: '{{ doc("prices_hour")}}' + tests: + - not_null + - name: ASSET_ID + description: '{{ doc("prices_asset_id") }}' + tests: + - not_null + - name: OPEN + description: '{{ doc("prices_open") }}' + - name: HIGH + description: '{{ doc("prices_high") }}' + - name: LOW + description: '{{ doc("prices_low") }}' + - name: CLOSE + description: '{{ doc("prices_close") }}' + tests: + - not_null + - name: FACT_PRICES_OHLC_HOURLY_ID + description: '{{ doc("pk") }}' + tests: + - not_null + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' \ No newline at end of file diff --git a/models/gold/stats/stats__ez_core_metrics_hourly.sql b/models/gold/stats/stats__ez_core_metrics_hourly.sql index 7f4722c..d773be6 100644 --- a/models/gold/stats/stats__ez_core_metrics_hourly.sql +++ b/models/gold/stats/stats__ez_core_metrics_hourly.sql @@ -15,7 +15,7 @@ WITH txs AS ( unique_from_count, total_fees AS total_fees_native, LAST_VALUE( - p.close ignore nulls + p.price ignore nulls ) over ( ORDER BY block_timestamp_hour rows unbounded preceding @@ -26,10 +26,10 @@ WITH txs AS ( FROM {{ ref('silver_stats__core_metrics_hourly') }} s - LEFT JOIN {{ ref('silver__hourly_prices_coin_gecko') }} + LEFT JOIN {{ ref('price__ez_prices_hourly') }} p - ON s.block_timestamp_hour = p.recorded_hour - AND p.id = 'sei-network' + ON s.block_timestamp_hour = p.hour + AND p.token_address = 'usei' ) SELECT A.block_timestamp_hour, diff --git a/models/silver/price/silver__complete_native_asset_metadata.sql b/models/silver/price/silver__complete_native_asset_metadata.sql new file mode 100644 index 0000000..3d062e6 --- /dev/null +++ b/models/silver/price/silver__complete_native_asset_metadata.sql @@ -0,0 +1,22 @@ +{{ 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 + {{ ref( + 'bronze__complete_native_asset_metadata' + ) }} diff --git a/models/silver/price/silver__complete_native_asset_metadata.yml b/models/silver/price/silver__complete_native_asset_metadata.yml new file mode 100644 index 0000000..030e19b --- /dev/null +++ b/models/silver/price/silver__complete_native_asset_metadata.yml @@ -0,0 +1,10 @@ +version: 2 +models: + - name: silver__complete_native_asset_metadata + + columns: + - name: PROVIDER + - name: SYMBOL + - name: BLOCKCHAIN + - name: MODIFIED_TIMESTAMP + - name: COMPLETE_NATIVE_ASSET_METADATA_ID \ No newline at end of file diff --git a/models/silver/price/silver__complete_native_prices.sql b/models/silver/price/silver__complete_native_prices.sql index bb798ba..485619f 100644 --- a/models/silver/price/silver__complete_native_prices.sql +++ b/models/silver/price/silver__complete_native_prices.sql @@ -1,8 +1,5 @@ {{ config( - materialized = 'incremental', - incremental_strategy = 'delete+insert', - unique_key = 'complete_native_prices_id', - tags = ['core'] + materialized = 'view' ) }} SELECT @@ -26,15 +23,3 @@ FROM {{ ref( 'bronze__complete_native_prices' ) }} - -{% if is_incremental() %} -WHERE - modified_timestamp >= ( - SELECT - MAX( - modified_timestamp - ) - FROM - {{ this }} - ) -{% endif %} diff --git a/models/silver/price/silver__complete_provider_asset_metadata.sql b/models/silver/price/silver__complete_provider_asset_metadata.sql new file mode 100644 index 0000000..52e21fa --- /dev/null +++ b/models/silver/price/silver__complete_provider_asset_metadata.sql @@ -0,0 +1,22 @@ +{{ 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 + {{ ref( + 'bronze__complete_provider_asset_metadata' + ) }} diff --git a/models/silver/price/silver__complete_provider_asset_metadata.yml b/models/silver/price/silver__complete_provider_asset_metadata.yml new file mode 100644 index 0000000..a4b2828 --- /dev/null +++ b/models/silver/price/silver__complete_provider_asset_metadata.yml @@ -0,0 +1,8 @@ +version: 2 +models: + - name: silver__complete_provider_asset_metadata + columns: + - name: PROVIDER + - name: ASSET_ID + - name: MODIFIED_TIMESTAMP + - name: COMPLETE_PROVIDER_ASSET_METADATA_ID diff --git a/models/silver/price/silver__complete_provider_prices.sql b/models/silver/price/silver__complete_provider_prices.sql new file mode 100644 index 0000000..ed08904 --- /dev/null +++ b/models/silver/price/silver__complete_provider_prices.sql @@ -0,0 +1,47 @@ +{{ config( + materialized = 'incremental', + incremental_strategy = 'delete+insert', + unique_key = 'complete_provider_prices_id', + cluster_by = ['recorded_hour::DATE'], + post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(asset_id)", + tags = ['core'] +) }} + +SELECT + p.asset_id, + recorded_hour, + OPEN, + high, + low, + CLOSE, + p.provider, + p.source, + p._inserted_timestamp, + p.inserted_timestamp, + p.modified_timestamp, + p.complete_provider_prices_id, + p._invocation_id +FROM + {{ ref( + 'bronze__complete_provider_prices' + ) }} + p + INNER JOIN {{ ref('bronze__complete_provider_asset_metadata') }} + m + ON p.asset_id = m.asset_id + +{% if is_incremental() %} +WHERE + p.modified_timestamp >= ( + SELECT + MAX( + modified_timestamp + ) + FROM + {{ this }} + ) +{% endif %} + +qualify(ROW_NUMBER() over (PARTITION BY p.asset_id, recorded_hour, p.provider +ORDER BY + p.modified_timestamp DESC)) = 1 diff --git a/models/silver/price/silver__complete_provider_prices.yml b/models/silver/price/silver__complete_provider_prices.yml new file mode 100644 index 0000000..8db23c7 --- /dev/null +++ b/models/silver/price/silver__complete_provider_prices.yml @@ -0,0 +1,25 @@ +version: 2 +models: + - name: silver__complete_provider_prices + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - ASSET_ID + - RECORDED_HOUR + - PROVIDER + columns: + - name: PROVIDER + tests: + - not_null + - name: ASSET_ID + tests: + - not_null + - name: RECORDED_HOUR + tests: + - not_null + - name: MODIFIED_TIMESTAMP + tests: + - not_null + - name: COMPLETE_PROVIDER_PRICES_ID + tests: + - unique \ No newline at end of file diff --git a/models/silver/price/silver__complete_token_asset_metadata.sql b/models/silver/price/silver__complete_token_asset_metadata.sql new file mode 100644 index 0000000..fad8367 --- /dev/null +++ b/models/silver/price/silver__complete_token_asset_metadata.sql @@ -0,0 +1,27 @@ +{{ config( + materialized = 'view' +) }} + +SELECT + LOWER( + A.token_address + ) AS 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 + {{ ref( + 'bronze__complete_token_asset_metadata' + ) }} A diff --git a/models/silver/price/silver__complete_token_asset_metadata.yml b/models/silver/price/silver__complete_token_asset_metadata.yml new file mode 100644 index 0000000..2103167 --- /dev/null +++ b/models/silver/price/silver__complete_token_asset_metadata.yml @@ -0,0 +1,10 @@ +version: 2 +models: + - name: silver__complete_token_asset_metadata + columns: + - name: PROVIDER + - name: TOKEN_ADDRESS + - name: BLOCKCHAIN + - name: BLOCKCHAIN_ID + - name: MODIFIED_TIMESTAMP + - name: COMPLETE_TOKEN_ASSET_METADATA_ID diff --git a/models/silver/price/silver__complete_token_prices.sql b/models/silver/price/silver__complete_token_prices.sql new file mode 100644 index 0000000..60671f7 --- /dev/null +++ b/models/silver/price/silver__complete_token_prices.sql @@ -0,0 +1,31 @@ +{{ config( + materialized = 'view' +) }} + +SELECT + HOUR, + LOWER( + p.token_address + ) AS 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 + {{ ref( + 'bronze__complete_token_prices' + ) }} + p diff --git a/models/silver/price/silver__complete_token_prices.yml b/models/silver/price/silver__complete_token_prices.yml new file mode 100644 index 0000000..f06cac6 --- /dev/null +++ b/models/silver/price/silver__complete_token_prices.yml @@ -0,0 +1,15 @@ +version: 2 +models: + - name: silver__complete_token_prices + + columns: + - name: HOUR + - name: TOKEN_ADDRESS + - name: BLOCKCHAIN + - name: BLOCKCHAIN_ID + - name: PROVIDER + - name: PRICE + - name: IS_IMPUTED + - name: _INSERTED_TIMESTAMP + - name: MODIFIED_TIMESTAMP + - name: COMPLETE_TOKEN_PRICES_ID \ No newline at end of file diff --git a/models/sources.yml b/models/sources.yml index ccbd5da..c828043 100644 --- a/models/sources.yml +++ b/models/sources.yml @@ -31,6 +31,10 @@ sources: - name: labels_combined - name: complete_native_asset_metadata - name: complete_native_prices + - name: complete_token_asset_metadata + - name: complete_token_prices + - name: complete_provider_asset_metadata + - name: complete_provider_prices - name: bronze_streamline database: streamline schema: |