An 3747/op new views (#169)

* new views

* new views

* add price docs

* add current tables

* data studio docs update

* moved tables

* moved tables

* add yml for prices

* add inserted timestamp
This commit is contained in:
Sam 2023-09-01 01:11:00 +08:00 committed by GitHub
parent 1b3fa9ac1f
commit 71719abb13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 713 additions and 160 deletions

View File

@ -15,7 +15,7 @@ SELECT
FROM
{{ source(
'crosschain',
'address_labels'
'dim_labels'
) }}
WHERE
blockchain = 'optimism'

View File

@ -0,0 +1,19 @@
{{ config (
materialized = 'view'
) }}
SELECT
token_address,
id,
symbol,
blockchain,
provider,
_unique_key,
_inserted_timestamp
FROM
{{ source(
'silver_crosschain',
'asset_metadata_all_providers'
) }}
WHERE
blockchain = 'optimism'

View File

@ -0,0 +1,20 @@
{{ config (
materialized = 'view'
) }}
SELECT
HOUR,
token_address,
blockchain,
provider,
price,
is_imputed,
_inserted_timestamp,
_unique_key
FROM
{{ source(
'silver_crosschain',
'token_prices_all_providers_hourly'
) }}
WHERE
blockchain = 'optimism'

View File

@ -30,21 +30,25 @@ There is more information on how to use dbt docs in the last section of this doc
- [fact_token_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_token_transfers)
- [fact_traces](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_traces)
- [fact_transactions](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_transactions)
- [fact_delegations](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_delegations)
- [fact_l1_state_root_submissions](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_l1_state_root_submissions)
- [fact_l1_submissions](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_l1_submissions)
- [fact_hourly_token_prices](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__fact_hourly_token_prices)
**Convenience Tables:**
- [ez_dex_swaps](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_dex_swaps)
- [ez_eth_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_eth_transfers)
- [ez_token_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_token_transfers)
- [ez_nft_sales](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_nft_sales)
- [ez_decoded_event_logs](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_decoded_event_logs)
- [ez_nft_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.core__ez_nft_transfers)
### 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)
- [ez_asset_metadata](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.price__ez_asset_metadata)
### DeFi Tables (optimism.defi)
- [dim_dex_liquidity_pools](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__dim_dex_liquidity_pools)
- [ez_dex_swaps](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.defi__ez_dex_swaps)
**Velodrome**
- [ez_claimed_rewards](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_claimed_rewards)
@ -55,6 +59,14 @@ There is more information on how to use dbt docs in the last section of this doc
- [ez_velo_locks](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_velo_locks)
- [ez_votes](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_votes)
### NFT Tables (optimism.nft)
- [ez_nft_sales](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.nft__ez_nft_sales)
- [ez_nft_transfers](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.nft__ez_nft_transfers)
### Governance Tables (optimism.gov)
- [fact_delegations](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.gov__fact_delegations)
## **Helpful User-Defined Functions (UDFs)**
UDFs are custom functions built by the Flipside team that can be used in your queries to make your life easier.
@ -97,7 +109,7 @@ Note that you can also right-click on models to interactively filter and explore
- [Flipside](https://flipsidecrypto.xyz)
- [Tutorials](https://docs.flipsidecrypto.com/our-data/tutorials)
- [Github](https://github.com/FlipsideCrypto/optimism-models)
- [Query Editor Shortcuts](https://docs.flipsidecrypto.com/velocity/query-editor-shortcuts)
- [Data Studio](https://flipsidecrypto.xyz/edit)
- [What is dbt?](https://docs.getdbt.com/docs/introduction)
{% enddocs %}

View File

@ -98,7 +98,7 @@ SELECT
_inserted_timestamp
FROM
eth_base A
LEFT JOIN {{ ref('silver__prices_eth') }}
LEFT JOIN {{ ref('silver__hourly_prices_priority_eth') }}
ON DATE_TRUNC(
'hour',
A.block_timestamp

View File

@ -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(

View File

@ -13,27 +13,6 @@
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
pool_name,
event_name,
amount_in,
amount_in_usd,
amount_out,
amount_out_usd,
sender,
tx_to,
event_index,
platform,
token_in,
token_out,
symbol_in,
symbol_out,
_log_id
*
FROM
{{ ref('silver_dex__complete_dex_swaps') }}
{{ ref('defi__ez_dex_swaps') }}

View File

@ -1,7 +1,7 @@
version: 2
models:
- name: core__ez_dex_swaps
description: '{{ doc("eth_ez_dex_swaps_table_doc") }}'
description: Deprecating soon! This is a notice that we're replacing this table with `defi__ez_dex_swaps`. 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: BLOCK_NUMBER

View File

@ -0,0 +1,39 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PROTOCOL': 'SUSHI, UNISWAP, CURVE, SYNTHETIX, VELODROME, WOOFI, FRAX, KYBERSWAP, DODO',
'PURPOSE': 'DEX, SWAPS'
}
}
}
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
pool_name,
event_name,
amount_in,
amount_in_usd,
amount_out,
amount_out_usd,
sender,
tx_to,
event_index,
platform,
token_in,
token_out,
symbol_in,
symbol_out,
_log_id
FROM
{{ ref('silver_dex__complete_dex_swaps') }}

View File

@ -0,0 +1,48 @@
version: 2
models:
- name: defi__ez_dex_swaps
description: '{{ doc("eth_ez_dex_swaps_table_doc") }}'
columns:
- name: BLOCK_NUMBER
description: '{{ doc("opt_block_number") }}'
- name: BLOCK_TIMESTAMP
description: '{{ doc("opt_block_timestamp") }}'
- name: TX_HASH
description: '{{ doc("opt_logs_tx_hash") }}'
- name: CONTRACT_ADDRESS
description: '{{ doc("opt_logs_contract_address") }}'
- name: EVENT_NAME
description: '{{ doc("opt_event_name") }}'
- name: AMOUNT_IN
description: '{{ doc("eth_dex_swaps_amount_in") }}'
- name: AMOUNT_OUT
description: '{{ doc("eth_dex_swaps_amount_out") }}'
- name: AMOUNT_IN_USD
description: '{{ doc("eth_dex_swaps_amount_in_usd") }}'
- name: AMOUNT_OUT_USD
description: '{{ doc("eth_dex_swaps_amount_out_usd") }}'
- name: TOKEN_IN
description: '{{ doc("eth_dex_swaps_token_in") }}'
- name: TOKEN_OUT
description: '{{ doc("eth_dex_swaps_token_out") }}'
- name: SYMBOL_IN
description: '{{ doc("eth_dex_swaps_symbol_in") }}'
- name: SYMBOL_OUT
description: '{{ doc("eth_dex_swaps_symbol_out") }}'
- name: SENDER
description: '{{ doc("eth_dex_swaps_sender") }}'
- name: TX_TO
description: '{{ doc("eth_dex_swaps_tx_to") }}'
- name: PLATFORM
description: '{{ doc("eth_dex_platform") }}'
- name: EVENT_INDEX
description: '{{ doc("opt_event_index") }}'
- name: _LOG_ID
description: '{{ doc("opt_log_id_events") }}'
- name: ORIGIN_FUNCTION_SIGNATURE
description: '{{ doc("opt_tx_origin_sig") }}'
- name: ORIGIN_FROM_ADDRESS
description: '{{ doc("opt_origin_from") }}'
- name: ORIGIN_TO_ADDRESS
description: '{{ doc("opt_origin_to") }}'

View File

@ -4,19 +4,7 @@
"columns": true }
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
status,
event_name,
delegator,
to_delegate,
from_delegate,
delegation_type,
new_balance,
previous_balance,
raw_new_balance,
raw_previous_balance
FROM
{{ ref('silver__delegations') }}
SELECT
*
FROM
{{ ref('gov__fact_delegations') }}

View File

@ -1,7 +1,8 @@
version: 2
models:
- name: core__fact_delegations
description: '{{ doc("opt_delegations_table_doc") }}'
description: Deprecating soon! This is a notice that we're replacing this table with `gov__fact_delegations`. 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: BLOCK_NUMBER
description: '{{ doc("opt_block_number") }}'

View File

@ -0,0 +1,22 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true }
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
status,
event_name,
delegator,
to_delegate,
from_delegate,
delegation_type,
new_balance,
previous_balance,
raw_new_balance,
raw_previous_balance
FROM
{{ ref('silver__delegations') }}

View File

@ -0,0 +1,45 @@
version: 2
models:
- name: gov__fact_delegations
description: '{{ doc("opt_delegations_table_doc") }}'
columns:
- name: BLOCK_NUMBER
description: '{{ doc("opt_block_number") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: BLOCK_TIMESTAMP
description: '{{ doc("opt_block_timestamp") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: TX_HASH
description: '{{ doc("opt_tx_hash") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: STATUS
description: '{{ doc("opt_tx_status") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: DELEGATOR
description: '{{ doc("delegation_delegator") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: TO_DELEGATE
description: '{{ doc("delegation_to_delegate") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: FROM_DELEGATE
description: '{{ doc("delegation_from_delegate") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: DELEGATION_TYPE
description: '{{ doc("delegation_delegation_type") }}'
tests:
- dbt_expectations.expect_column_to_exist
- name: RAW_NEW_BALANCE
description: The new amount the user has delegated after the transaction
tests:
- dbt_expectations.expect_column_to_exist
- name: RAW_PREVIOUS_BALANCE
description: The amount of OP the user had delegated before the transaction.
tests:
- dbt_expectations.expect_column_to_exist

View File

@ -12,31 +12,6 @@
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
event_type,
platform_address,
platform_name,
platform_exchange_version,
seller_address,
buyer_address,
nft_address,
project_name,
tokenId,
erc1155_value,
currency_symbol,
currency_address,
price,
price_usd,
total_fees,
platform_fee,
creator_fee,
total_fees_usd,
platform_fee_usd,
creator_fee_usd,
origin_from_address,
origin_to_address,
origin_function_signature
*
FROM
{{ ref('silver__complete_nft_sales') }}
{{ ref('nft__ez_nft_sales') }}

View File

@ -1,8 +1,8 @@
version: 2
models:
- name: core__ez_nft_sales
description: 'This table contains NFT sale events on the Optimism blockchain which includes Quixotic and Opensea.'
description: Deprecating soon! This is a notice that we're replacing this table with `nft__ez_nft_sales`. 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: BLOCK_NUMBER
description: '{{ doc("nft_block_no") }}'

View File

@ -2,24 +2,10 @@
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'NFT'
}
}
}
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'NFT' } } }
) }}
SELECT
block_timestamp,
block_number,
tx_hash,
event_index,
event_type,
contract_address AS nft_address,
project_name,
from_address AS nft_from_address,
to_address AS nft_to_address,
tokenId,
erc1155_value
*
FROM
{{ ref('silver__nft_transfers') }}
{{ ref('nft__ez_nft_transfers') }}

View File

@ -1,7 +1,7 @@
version: 2
models:
- name: core__ez_nft_transfers
description: '{{ doc("nft_transfer_doc") }}'
description: Deprecating soon! This is a notice that we're replacing this table with `nft__ez_nft_transfers`. 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: BLOCK_NUMBER

View File

@ -0,0 +1,42 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta={
'database_tags':{
'table': {
'PURPOSE': 'NFT'
}
}
}
) }}
SELECT
block_number,
block_timestamp,
tx_hash,
event_type,
platform_address,
platform_name,
platform_exchange_version,
seller_address,
buyer_address,
nft_address,
project_name,
tokenId,
erc1155_value,
currency_symbol,
currency_address,
price,
price_usd,
total_fees,
platform_fee,
creator_fee,
total_fees_usd,
platform_fee_usd,
creator_fee_usd,
origin_from_address,
origin_to_address,
origin_function_signature
FROM
{{ ref('silver__complete_nft_sales') }}

View File

@ -0,0 +1,56 @@
version: 2
models:
- name: nft__ez_nft_sales
description: 'This table contains NFT sale events on the Optimism blockchain which includes Quixotic and Opensea.'
columns:
- name: BLOCK_NUMBER
description: '{{ doc("nft_block_no") }}'
- name: BLOCK_TIMESTAMP
description: '{{ doc("nft_blocktime") }}'
- name: TX_HASH
description: '{{ doc("nft_tx_hash") }}'
- name: EVENT_TYPE
description: '{{ doc("nft_event_type") }}'
- name: PLATFORM_ADDRESS
description: '{{ doc("nft_platform_address") }}'
- name: PLATFORM_NAME
description: '{{ doc("nft_platform_name") }}'
- name: PLATFORM_EXCHANGE_VERSION
description: '{{ doc("nft_platform_exchange_version") }}'
- name: SELLER_ADDRESS
description: '{{ doc("nft_seller_address") }}'
- name: BUYER_ADDRESS
description: '{{ doc("nft_buyer_address") }}'
- name: NFT_ADDRESS
description: '{{ doc("nft_nft_address") }}'
- name: TOKENID
description: '{{ doc("nft_tokenid") }}'
- name: ERC1155_VALUE
description: '{{ doc("nft_erc1155_value") }}'
- name: CURRENCY_SYMBOL
description: '{{ doc("nft_currency_symbol") }}'
- name: CURRENCY_ADDRESS
description: '{{ doc("nft_currency_address") }}'
- name: PRICE
description: '{{ doc("nft_price") }}'
- name: PRICE_USD
description: '{{ doc("nft_price_usd") }}'
- name: TOTAL_FEES
description: '{{ doc("nft_total_fees") }}'
- name: PLATFORM_FEE
description: '{{ doc("nft_platform_fee") }}'
- name: CREATOR_FEE
description: '{{ doc("nft_creator_fee") }}'
- name: TOTAL_FEES_USD
description: '{{ doc("nft_total_fees_usd") }}'
- name: PLATFORM_FEE_USD
description: '{{ doc("nft_platform_fee_usd") }}'
- name: CREATOR_FEE_USD
description: '{{ doc("nft_creator_fee_usd") }}'
- name: ORIGIN_FROM_ADDRESS
description: '{{ doc("nft_origin_from") }}'
- name: ORIGIN_TO_ADDRESS
description: '{{ doc("nft_origin_to") }}'
- name: ORIGIN_FUNCTION_SIGNATURE
description: '{{ doc("nft_origin_sig") }}'

View File

@ -0,0 +1,21 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true },
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'NFT' } } }
) }}
SELECT
block_timestamp,
block_number,
tx_hash,
event_index,
event_type,
contract_address AS nft_address,
project_name,
from_address AS nft_from_address,
to_address AS nft_to_address,
tokenId,
erc1155_value
FROM
{{ ref('silver__nft_transfers') }}

View File

@ -0,0 +1,66 @@
version: 2
models:
- name: nft__ez_nft_transfers
description: '{{ doc("nft_transfer_doc") }}'
columns:
- name: BLOCK_NUMBER
description: '{{ doc("nft_block_no") }}'
- name: BLOCK_TIMESTAMP
description: '{{ doc("nft_blocktime") }}'
- name: TX_HASH
description: '{{ doc("nft_tx_hash") }}'
- name: EVENT_TYPE
description: '{{ doc("nft_event_type") }}'
- name: PLATFORM_ADDRESS
description: '{{ doc("nft_platform_address") }}'
- name: PLATFORM_NAME
description: '{{ doc("nft_platform_name") }}'
- name: PLATFORM_EXCHANGE_VERSION
description: '{{ doc("nft_platform_exchange_version") }}'
- name: AGGREGATOR_NAME
description: '{{ doc("nft_aggregator_name") }}'
- name: SELLER_ADDRESS
description: '{{ doc("nft_seller_address") }}'
- name: BUYER_ADDRESS
description: '{{ doc("nft_buyer_address") }}'
- name: NFT_ADDRESS
description: '{{ doc("nft_nft_address") }}'
- name: PROJECT_NAME
description: '{{ doc("nft_project_name") }}'
- name: ERC1155_VALUE
description: '{{ doc("nft_erc1155_value") }}'
- name: TOKENID
description: '{{ doc("nft_tokenid") }}'
- name: TOKEN_METADATA
description: '{{ doc("nft_metadata") }}'
- name: CURRENCY_SYMBOL
description: '{{ doc("nft_currency_symbol") }}'
- name: CURRENCY_ADDRESS
description: '{{ doc("nft_currency_address") }}'
- name: PRICE
description: '{{ doc("nft_price") }}'
- name: PRICE_USD
description: '{{ doc("nft_price_usd") }}'
- name: TOTAL_FEES
description: '{{ doc("nft_total_fees") }}'
- name: PLATFORM_FEE
description: '{{ doc("nft_platform_fee") }}'
- name: CREATOR_FEE
description: '{{ doc("nft_creator_fee") }}'
- name: TOTAL_FEES_USD
description: '{{ doc("nft_total_fees_usd") }}'
- name: PLATFORM_FEE_USD
description: '{{ doc("nft_platform_fee_usd") }}'
- name: CREATOR_FEE_USD
description: '{{ doc("nft_creator_fee_usd") }}'
- name: TX_FEE
description: '{{ doc("nft_tx_fee") }}'
- name: TX_FEE_USD
description: '{{ doc("nft_tx_fee_usd") }}'
- name: ORIGIN_FROM_ADDRESS
description: '{{ doc("nft_origin_from") }}'
- name: ORIGIN_TO_ADDRESS
description: '{{ doc("nft_origin_to") }}'
- name: ORIGIN_FUNCTION_SIGNATURE
description: '{{ doc("nft_origin_sig") }}'

View File

@ -0,0 +1,10 @@
{{ config(
materialized = 'view',
persist_docs ={ "relation": true,
"columns": true }
) }}
SELECT
*
FROM
{{ ref('price__ez_hourly_token_prices') }}

View File

@ -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 Optimism 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
@ -10,7 +10,7 @@ models:
tests:
- not_null
- name: TOKEN_ADDRESS
description: 'The Optimism contract address for this token. This is the column used to join to token contract addresses in the other event tables.'
description: 'The contract address for this token. This is the column used to join to token contract addresses in the other event tables.'
tests:
- not_null
- name: SYMBOL

View File

@ -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') }}

View File

@ -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.

View File

@ -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') }}

View File

@ -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.

View File

@ -12,4 +12,4 @@ SELECT
price,
is_imputed
FROM
{{ ref('silver__prices') }}
{{ ref('silver__hourly_prices_priority') }}

View File

@ -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)

View File

@ -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') }}

View File

@ -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)

View File

@ -93,7 +93,7 @@ FROM
base
LEFT JOIN tokens t
ON t.token_address = base.token_address
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
prices
ON HOUR = DATE_TRUNC(
'hour',

View File

@ -70,14 +70,14 @@ FROM
) = LOWER(
pools.pool_address
)
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
p0
ON p0.hour = DATE_TRUNC(
'hour',
block_timestamp
)
AND token0_address = p0.token_address
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
p1
ON p1.hour = DATE_TRUNC(
'hour',

View File

@ -183,7 +183,7 @@ FROM
)
LEFT JOIN tokens
ON tokens.token_address = fee_currency
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
p0
ON p0.hour = DATE_TRUNC(
'hour',
@ -193,7 +193,7 @@ FROM
WHEN amount0_in_unadj <> 0 THEN token0_address
WHEN amount1_in_unadj <> 0 THEN token1_address
END
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
p1
ON p1.hour = DATE_TRUNC(
'hour',
@ -203,7 +203,7 @@ FROM
WHEN amount0_out_unadj <> 0 THEN token0_address
WHEN amount1_out_unadj <> 0 THEN token1_address
END
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
p2
ON p2.hour = DATE_TRUNC(
'hour',

View File

@ -33,7 +33,7 @@ SELECT
deposit_type
FROM
{{ ref('silver__velodrome_locks') }}
LEFT JOIN {{ ref('core__fact_hourly_token_prices') }}
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
prices
ON HOUR = DATE_TRUNC(
'hour',

View File

@ -21,7 +21,7 @@ prices AS (
token_address,
price
FROM
{{ ref('core__fact_hourly_token_prices') }}
{{ ref('price__ez_hourly_token_prices') }}
WHERE
token_address IN (
SELECT

View File

@ -220,7 +220,7 @@ prices_raw AS (
decimals,
price AS hourly_prices
FROM
{{ ref('core__fact_hourly_token_prices') }}
{{ ref('price__ez_hourly_token_prices') }}
WHERE
token_address IN (
SELECT

View File

@ -1,35 +0,0 @@
{{ config(
materialized = 'incremental',
unique_key = 'token_address',
tags = ['non_realtime']
) }}
SELECT
token_address,
symbol,
provider,
id,
CASE
WHEN provider = 'coingecko' THEN 1
WHEN provider = 'coinmarketcap' THEN 2
END AS priority,
_inserted_timestamp
FROM
{{ ref('bronze__asset_metadata') }}
WHERE
1 = 1
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(
_inserted_timestamp
)
FROM
{{ this }}
)
{% endif %}
qualify(ROW_NUMBER() over (PARTITION BY token_address
ORDER BY
priority ASC)) = 1

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,45 @@
{{ config(
materialized = 'incremental',
unique_key = 'token_address',
tags = ['non_realtime']
) }}
SELECT
p.token_address,
p.id,
COALESCE(
C.token_symbol,
p.symbol
) AS symbol,
C.token_name AS name,
C.token_decimals AS decimals,
p.provider,
CASE
WHEN p.provider = 'coingecko' THEN 1
WHEN p.provider = 'coinmarketcap' THEN 2
END AS priority,
p._inserted_timestamp
FROM
{{ ref('bronze__asset_metadata_priority') }}
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
ORDER BY
priority ASC)) = 1

View File

@ -0,0 +1,12 @@
version: 2
models:
- name: silver__asset_metadata_priority
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TOKEN_ADDRESS
columns:
- name: TOKEN_ADDRESS
tests:
- not_null

View File

@ -1,17 +1,18 @@
{{ config(
materialized = 'incremental',
unique_key = ['token_address', 'hour'],
unique_key = ['token_address', 'hour', 'provider'],
tags = ['non_realtime']
) }}
SELECT
HOUR,
token_address,
provider,
price,
is_imputed,
_inserted_timestamp
FROM
{{ ref('bronze__hourly_prices') }}
{{ ref('bronze__hourly_prices_all_providers') }}
WHERE
1 = 1

View File

@ -0,0 +1,17 @@
version: 2
models:
- name: silver__hourly_prices_all_providers
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TOKEN_ADDRESS
- HOUR
- PROVIDER
columns:
- name: HOUR
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 1

View File

@ -16,9 +16,9 @@ SELECT
) AS symbol,
C.token_decimals AS decimals
FROM
{{ ref('silver__hourly_prices') }}
{{ ref('bronze__hourly_prices_priority') }}
p
LEFT JOIN {{ ref('silver__asset_metadata') }}
LEFT JOIN {{ ref('silver__asset_metadata_priority') }}
m
ON p.token_address = m.token_address
LEFT JOIN {{ ref('silver__contracts') }} C
@ -35,4 +35,4 @@ AND p._inserted_timestamp >= (
FROM
{{ this }}
)
{% endif %}
{% endif %}

View File

@ -1,6 +1,6 @@
version: 2
models:
- name: silver__prices
- name: silver__hourly_prices_priority
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:

View File

@ -11,7 +11,7 @@ SELECT
is_imputed,
_inserted_timestamp
FROM
{{ ref('bronze__hourly_prices_eth') }}
{{ ref('bronze__hourly_prices_priority_eth') }}
WHERE
1 = 1

View File

@ -1,6 +1,6 @@
version: 2
models:
- name: silver__prices_eth
- name: silver__hourly_prices_priority_eth
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:

View File

@ -8,11 +8,11 @@ sources:
- name: optimism_blocks
- name: optimism_txs
- name: crosschain
database: crosschain
database: "{{ 'crosschain' if target.database == 'OPTIMISM' else 'crosschain_dev' }}"
schema: core
tables:
- name: address_labels
- name: ez_hourly_prices
- name: dim_labels
- name: ez_hourly_token_prices
- name: ethereum
database: ethereum
schema: core
@ -25,16 +25,14 @@ sources:
- name: optimism_state_hashes
- name: optimism_submission_hashes
- name: silver_crosschain
database: crosschain
database: "{{ 'crosschain' if target.database == 'OPTIMISM' else 'crosschain_dev' }}"
schema: silver
tables:
- name: asset_metadata_coin_gecko
- name: asset_metadata_coin_market_cap
- name: hourly_prices_coin_gecko
- name: hourly_prices_coin_market_cap
- name: apis_keys
- name: token_prices_priority_hourly
- name: token_prices_all_providers_hourly
- name: asset_metadata_priority
- name: asset_metadata_all_providers
- name: number_sequence
- name: streamline_crosschain
database: streamline