diff --git a/models/gold/core__fact_hourly_prices.yml b/models/gold/core__fact_hourly_prices.yml index 276d835..1dbcba9 100644 --- a/models/gold/core__fact_hourly_prices.yml +++ b/models/gold/core__fact_hourly_prices.yml @@ -7,7 +7,7 @@ models: This table provides hourly token price data for FLOW tokens from CoinGecko and CoinMarketCap. columns: - - name: recorded_hour + - name: RECORDED_HOUR description: "{{ doc('recorded_hour') }}" tests: - not_null @@ -15,7 +15,7 @@ models: column_type_list: - TIMESTAMP_NTZ - - name: id + - name: ID description: "{{ doc('asset_id') }}" tests: - not_null @@ -24,16 +24,15 @@ models: - STRING - VARCHAR - - name: token + - name: TOKEN description: "{{ doc('token') }}" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - STRING - VARCHAR - - name: open + - name: OPEN description: "{{ doc('open') }}" tests: - not_null @@ -42,7 +41,7 @@ models: - FLOAT - DOUBLE - - name: high + - name: HIGH description: "{{ doc('high') }}" tests: - not_null @@ -51,7 +50,7 @@ models: - FLOAT - DOUBLE - - name: low + - name: LOW description: "{{ doc('low') }}" tests: - not_null @@ -60,7 +59,7 @@ models: - FLOAT - DOUBLE - - name: close + - name: CLOSE description: "{{ doc('asset_id') }}" tests: - not_null @@ -69,7 +68,7 @@ models: - FLOAT - DOUBLE - - name: provider + - name: PROVIDER description: "{{ doc('provider') }}" tests: - not_null diff --git a/models/gold/core__fact_prices.sql b/models/gold/core__fact_prices.sql index cffda53..34d85a2 100644 --- a/models/gold/core__fact_prices.sql +++ b/models/gold/core__fact_prices.sql @@ -23,6 +23,7 @@ prices AS ( ), prices_swaps AS ( SELECT + tx_id, block_timestamp AS TIMESTAMP, token_contract, swap_price AS price_usd, @@ -37,7 +38,8 @@ viewnion AS ( p.symbol, l.token_contract, price_usd, - source + source, + NULL as tx_id FROM prices p LEFT JOIN token_labels l USING (symbol) @@ -48,7 +50,8 @@ viewnion AS ( l.symbol, ps.token_contract, price_usd, - source + source, + tx_id FROM prices_swaps ps LEFT JOIN token_labels l USING (token_contract) diff --git a/models/gold/core__fact_prices.yml b/models/gold/core__fact_prices.yml index e1810da..a1d4fa6 100644 --- a/models/gold/core__fact_prices.yml +++ b/models/gold/core__fact_prices.yml @@ -3,7 +3,9 @@ version: 2 models: - name: core__fact_prices description: |- - deprecating soon! This table is being deprecated in favor of the hourly prices table. Please move work over to that table. + This table reports prices derived from various on-chain sources. CoinGecko and CoinMarketCap price feeds can be found in the hourly price table. + Note that prices from swaps may be volatile and are an approximation of price in USD terms, at best. A tx_hash is included for prices from swaps to provide a source. + Low cap coins may have questionable prices due to low liquidity. columns: - name: TIMESTAMP @@ -17,7 +19,6 @@ models: - name: TOKEN description: "{{ doc('token') }}" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - STRING @@ -26,7 +27,6 @@ models: - name: SYMBOL description: "{{ doc('symbol') }}" tests: - - not_null - dbt_expectations.expect_column_values_to_be_in_type_list: column_type_list: - STRING diff --git a/models/silver/prices/silver__prices_swaps.sql b/models/silver/prices/silver__prices_swaps.sql index 2ea1458..6781e0d 100644 --- a/models/silver/prices/silver__prices_swaps.sql +++ b/models/silver/prices/silver__prices_swaps.sql @@ -17,10 +17,9 @@ WITH swaps AS ( token_out_contract, token_in_amount, token_in_contract, - _ingested_at, _inserted_timestamp FROM - {{ ref('silver__swaps_single_trade') }} + {{ ref('silver__swaps') }} {% if is_incremental() %} WHERE @@ -34,22 +33,19 @@ WHERE ), flow_price AS ( SELECT - DATE_TRUNC( - 'm', - recorded_at - ) AS _timestamp, - price_usd + recorded_hour as _timestamp, + open as price_usd FROM - {{ ref('silver__prices') }} + {{ ref('silver__prices_hourly') }} WHERE - symbol = 'FLOW' + token = 'Flow' ), stable_out AS ( SELECT tx_id, block_timestamp, token_in_contract AS token_contract, - token_out_amount / token_in_amount AS swap_price, + token_out_amount / nullifzero(token_in_amount) AS swap_price, _inserted_timestamp, 'stableswap' AS source FROM @@ -66,7 +62,7 @@ stable_in AS ( tx_id, block_timestamp, token_out_contract AS token_contract, - token_in_amount / token_out_amount AS swap_price, + token_in_amount / nullifzero(token_out_amount) AS swap_price, _inserted_timestamp, 'stableswap' AS source FROM @@ -94,7 +90,7 @@ flow_out AS ( tx_id, block_timestamp, token_in_contract AS token_contract, - token_out_amount / token_in_amount AS swap_price_in_flow, + token_out_amount / nullifzero(token_in_amount) AS swap_price_in_flow, _inserted_timestamp FROM swaps @@ -106,7 +102,7 @@ flow_in AS ( tx_id, block_timestamp, token_in_contract AS token_contract, - token_out_amount / token_in_amount AS swap_price_in_flow, + token_out_amount / nullifzero(token_in_amount) AS swap_price_in_flow, _inserted_timestamp FROM swaps @@ -117,7 +113,7 @@ flow_tbl_union AS ( SELECT tx_id, DATE_TRUNC( - 'm', + 'hour', block_timestamp ) AS _timestamp, token_contract, @@ -130,7 +126,7 @@ flow_tbl_union AS ( SELECT tx_id, DATE_TRUNC( - 'm', + 'hour', block_timestamp ) AS _timestamp, token_contract, @@ -180,3 +176,5 @@ SELECT * FROM FINAL +WHERE + swap_price IS NOT NULL diff --git a/profiles.yml b/profiles.yml index 374acd1..8c2adbc 100644 --- a/profiles.yml +++ b/profiles.yml @@ -6,7 +6,7 @@ flow: account: "{{ env_var('SF_ACCOUNT') }}" # User/password auth user: "{{ env_var('SF_USERNAME') }}" - password: "{{ env_var('SF_PASSWORD') }}" + authenticator: externalbrowser role: "{{ env_var('SF_ROLE') }}" schema: "{{ env_var('SF_SCHEMA') }}" region: "{{ env_var('SF_REGION') }}" @@ -16,4 +16,4 @@ flow: client_session_keep_alive: False query_tag: flow_curator config: - send_anonymous_usage_stats: False \ No newline at end of file + send_anonymous_usage_stats: False