mirror of
https://github.com/FlipsideCrypto/external-models.git
synced 2026-02-06 11:21:59 +00:00
Add bridge volume by chain defillama (#120)
This commit is contained in:
parent
985e98535a
commit
6e04a6d89b
@ -0,0 +1,29 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
tags = ['defillama'],
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'DEFILLAMA'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
DATE,
|
||||
chain,
|
||||
bridge_id,
|
||||
bridge,
|
||||
bridge_name,
|
||||
deposit_txs,
|
||||
deposit_usd,
|
||||
withdraw_txs,
|
||||
withdraw_usd,
|
||||
defillama_bridge_vol_by_chain_id as defillama_fact_bridge_volume_by_chain_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__defillama_bridge_volume_by_chain') }}
|
||||
@ -0,0 +1,30 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defillama__fact_bridge_volume_by_chain
|
||||
description: This table contains historical deposit and withdraw transaction volume for the bridges by chain listed on Defillama in `dim_bridges`. Only includes data for chains that are supported in the crosschain table.
|
||||
|
||||
columns:
|
||||
- name: DATE
|
||||
description: Date associated with the reported records.
|
||||
- name: CHAIN
|
||||
description: Chain associated with the reported records.
|
||||
- name: BRIDGE_ID
|
||||
description: Unique identifier of the bridge.
|
||||
- name: BRIDGE
|
||||
description: Name of the bridge.
|
||||
- name: BRIDGE_NAME
|
||||
description: The more descriptive, official display name of the bridge.
|
||||
- name: DEPOSIT_TXS
|
||||
description: Total number of deposit transactions to the bridge.
|
||||
- name: DEPOSIT_USD
|
||||
description: Total value of deposits to the bridge, denominated in USD.
|
||||
- name: WITHDRAW_TXS
|
||||
description: Total number of withdrawal transactions to the bridge.
|
||||
- name: WITHDRAW_USD
|
||||
description: Total value of withdrawals to the bridge, denominated in USD.
|
||||
- name: DEFILLAMA_FACT_BRIDGE_VOLUME_BY_CHAIN_ID
|
||||
description: Unique identifier for this record
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: Timestamp when the record was inserted
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: Timestamp when the record was last modified
|
||||
@ -0,0 +1,108 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = 'defillama_bridge_vol_by_chain_id',
|
||||
full_refresh = false,
|
||||
tags = ['defillama']
|
||||
) }}
|
||||
|
||||
WITH list_of_bridges AS (
|
||||
|
||||
SELECT
|
||||
bridge_id,
|
||||
bridge,
|
||||
bridge_name,
|
||||
LOWER(
|
||||
VALUE :: STRING
|
||||
) AS chain
|
||||
FROM
|
||||
{{ ref('bronze__defillama_bridges') }},
|
||||
LATERAL FLATTEN (
|
||||
input => chains
|
||||
)
|
||||
WHERE
|
||||
chain IN (
|
||||
SELECT
|
||||
DISTINCT blockchain
|
||||
FROM
|
||||
{{ source(
|
||||
'crosschain_defi',
|
||||
'ez_bridge_activity'
|
||||
) }}
|
||||
)
|
||||
),
|
||||
|
||||
build_requests as (
|
||||
select
|
||||
bridge_id,
|
||||
bridge,
|
||||
bridge_name,
|
||||
chain,
|
||||
CONCAT(bridge_id, '-', chain) AS bridge_id_chain,
|
||||
ROW_NUMBER() over (
|
||||
ORDER BY
|
||||
bridge_id_chain
|
||||
) AS row_number_request
|
||||
FROM
|
||||
list_of_bridges
|
||||
{% if is_incremental() %}
|
||||
where
|
||||
bridge_id_chain NOT IN
|
||||
(
|
||||
SELECT
|
||||
bridge_id_chain
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
bridge_id_chain,
|
||||
MAX(DATE) AS max_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
GROUP BY
|
||||
ALL
|
||||
HAVING
|
||||
SYSDATE()::date = max_timestamp)
|
||||
)
|
||||
{% endif %}) ,
|
||||
|
||||
requests AS (
|
||||
{% for item in range(10) %}
|
||||
SELECT
|
||||
bridge_id,
|
||||
bridge,
|
||||
bridge_name,
|
||||
chain,
|
||||
bridge_id_chain,
|
||||
live.udf_api('GET', CONCAT('https://bridges.llama.fi/bridgevolume/', chain, '?id=', bridge_id),{},{}) AS READ
|
||||
FROM
|
||||
build_requests
|
||||
WHERE
|
||||
row_number_request BETWEEN {{ item * 40 + 1 }}
|
||||
AND {{(item + 1) * 40 }}
|
||||
|
||||
{% if not loop.last %}
|
||||
UNION ALL
|
||||
{% endif %}
|
||||
{% endfor %})
|
||||
SELECT
|
||||
bridge_id,
|
||||
bridge,
|
||||
bridge_name,
|
||||
chain,
|
||||
bridge_id_chain,
|
||||
TO_TIMESTAMP(
|
||||
VALUE :date :: INTEGER
|
||||
)::DATE AS date,
|
||||
coalesce(VALUE :depositTxs :: INTEGER, 0) AS deposit_txs,
|
||||
coalesce(VALUE :depositUSD :: INTEGER, 0) AS deposit_usd,
|
||||
coalesce(VALUE :withdrawTxs :: INTEGER, 0) AS withdraw_txs,
|
||||
coalesce(VALUE :withdrawUSD :: INTEGER, 0) AS withdraw_usd,
|
||||
SYSDATE() as inserted_timestamp,
|
||||
SYSDATE() as modified_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['bridge_id_chain', 'date']) }} AS defillama_bridge_vol_by_chain_id,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
requests,
|
||||
LATERAL FLATTEN (
|
||||
input => READ :data
|
||||
)
|
||||
WHERE VALUE :depositTxs IS NOT NULL or VALUE :withdrawTxs IS NOT NULL
|
||||
@ -0,0 +1,42 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__defillama_bridge_volume_by_chain
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- defillama_bridge_vol_by_chain_id
|
||||
|
||||
columns:
|
||||
- name: BRIDGE_ID
|
||||
tests:
|
||||
- not_null
|
||||
- name: BRIDGE
|
||||
tests:
|
||||
- not_null
|
||||
- name: CHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: DATE
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSIT_TXS
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSIT_USD
|
||||
tests:
|
||||
- not_null
|
||||
- name: WITHDRAW_TXS
|
||||
tests:
|
||||
- not_null
|
||||
- name: WITHDRAW_USD
|
||||
tests:
|
||||
- not_null
|
||||
- name: INSERTED_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 2
|
||||
@ -34,6 +34,7 @@ Note: These tables ceased updating on Feburary 4th, 2024.
|
||||
- [defillama__dim_protocols](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__dim_protocols)
|
||||
- [defillama__dim_stablecoins](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__dim_stablecoins)
|
||||
- [defillama__fact_bridge_volume](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_bridge_volume)
|
||||
- [defillama__fact_bridge_volume_by_chain](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_bridge_volume_by_chain)
|
||||
- [defillama__fact_chain_tvl](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_chain_tvl)
|
||||
- [defillama__fact_dex_volume](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_dex_volume)
|
||||
- [defillama__fact_options_volume](https://flipsidecrypto.github.io/external-models/#!/model/model.external_models.defillama__fact_options_volume)
|
||||
|
||||
@ -34,6 +34,11 @@ sources:
|
||||
schema: core
|
||||
tables:
|
||||
- name: dim_dates
|
||||
- name: crosschain_defi
|
||||
database: crosschain
|
||||
schema: defi
|
||||
tables:
|
||||
- name: ez_bridge_activity
|
||||
- name: ethereum_silver
|
||||
database: ethereum
|
||||
schema: silver
|
||||
|
||||
Loading…
Reference in New Issue
Block a user