mirror of
https://github.com/FlipsideCrypto/terra-models.git
synced 2026-02-06 11:06:49 +00:00
Remove legacy sources, documentation, tests
This commit is contained in:
parent
da5a27ae19
commit
23c9949631
2
.github/workflows/dbt_run_daily.yml
vendored
2
.github/workflows/dbt_run_daily.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
uses: FlipsideCrypto/analytics-workflow-templates/.github/workflows/dbt_run_template.yml@main
|
||||
with:
|
||||
dbt_command: >
|
||||
dbt seed; dbt run
|
||||
dbt seed; dbt run --exclude tag:classic
|
||||
environment: workflow_prod
|
||||
warehouse: ${{ vars.WAREHOUSE }}
|
||||
secrets: inherit
|
||||
|
||||
2
.github/workflows/dbt_test.yml
vendored
2
.github/workflows/dbt_test.yml
vendored
@ -41,4 +41,4 @@ jobs:
|
||||
dbt deps
|
||||
- name: Run DBT Jobs
|
||||
run: |
|
||||
dbt test
|
||||
dbt test --exclude tag:classic
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, contract_address)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'astroport', 'pool_reserves']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
DISTINCT (
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
r.value :chain_id :: STRING AS chain_id,
|
||||
r.value :block_id :: INT AS block_id,
|
||||
r.value :blockchain :: STRING AS blockchain,
|
||||
r.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
r.value :contract_address :: STRING AS contract_address,
|
||||
r.value :value_obj :total_share :: INTEGER AS total_share,
|
||||
r.value :value_obj :asset_1 :: STRING AS token_0_currency,
|
||||
r.value :value_obj :asset_1_value :: INTEGER AS token_0_amount,
|
||||
r.value :value_obj :asset_2 :: STRING AS token_1_currency,
|
||||
r.value :value_obj :asset_2_value :: INTEGER AS token_1_amount
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }},
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) AS r
|
||||
WHERE
|
||||
(
|
||||
record_content :model.name = 'terra-5_astroport_pool_reserves'
|
||||
OR record_content :model.name = 'terra-5_astroport_pool_reserves_bison'
|
||||
OR record_content :model.name = 'terra-5_astroport_pool_reserves_backfill'
|
||||
)
|
||||
AND block_id >= 5840738
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND (
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP :: DATE >= (
|
||||
SELECT
|
||||
DATEADD('day', -1, MAX(system_created_at :: DATE))
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
51
models/bronze/classic/bronze__classic_balances.sql
Normal file
51
models/bronze/classic/bronze__classic_balances.sql
Normal file
@ -0,0 +1,51 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "_inserted_timestamp::date",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_balances']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content :model :class :: STRING IN (
|
||||
'terra.balances.models.Terra5BalancesModel',
|
||||
'terra.balances.models.Terra5DelegationsModel',
|
||||
'terra.balances.models.TerraBalancesModel',
|
||||
'terra.balances.models.TerraDelegationsModel'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :address :: STRING AS address,
|
||||
t.value :balance :: FLOAT AS balance,
|
||||
t.value :balance_type :: STRING AS balance_type,
|
||||
t.value :block_id :: INT AS block_number,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :currency :: STRING AS currency
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
48
models/bronze/classic/bronze__classic_blocks.sql
Normal file
48
models/bronze/classic/bronze__classic_blocks.sql
Normal file
@ -0,0 +1,48 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_blocks']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content :model :name :: STRING IN (
|
||||
'terra_block_model',
|
||||
'terra-5_block_model'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
record_content :model :blockchain :: STRING AS chain_id,
|
||||
t.value :block_id :: INT AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :proposer_address :: STRING AS proposer_address,
|
||||
t.value :num_txs :: int AS tx_count
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
61
models/bronze/classic/bronze__classic_msg_events.sql
Normal file
61
models/bronze/classic/bronze__classic_msg_events.sql
Normal file
@ -0,0 +1,61 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, tx_id, msg_index, event_index)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_msg_events']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content :model :name :: STRING IN (
|
||||
'terra_msg_event_model',
|
||||
'terra-5_msg_event_model'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :block_id :: bigint AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :chain_id :: STRING AS chain_id,
|
||||
COALESCE(
|
||||
t.value :txhash :: STRING,
|
||||
-- Pre Columbus-5: tx_id
|
||||
-- Post Columbus-4: txhash
|
||||
t.value :tx_id :: STRING
|
||||
) AS tx_id,
|
||||
t.value :tx_module :: STRING AS tx_module,
|
||||
t.value :tx_status :: STRING AS tx_status,
|
||||
t.value :tx_type :: STRING AS tx_type,
|
||||
t.value :msg_index :: INTEGER AS msg_index,
|
||||
t.value :msg_type :: STRING AS msg_type,
|
||||
t.value :msg_module :: STRING AS msg_module,
|
||||
t.value :event_type :: STRING AS event_type,
|
||||
t.value :event_index :: INTEGER AS event_index,
|
||||
t.value :event_attributes :: OBJECT AS event_attributes
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
63
models/bronze/classic/bronze__classic_msg_events_actions.sql
Normal file
63
models/bronze/classic/bronze__classic_msg_events_actions.sql
Normal file
@ -0,0 +1,63 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, tx_id, msg_index, event_index)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'event_actions']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content :model :name :: STRING IN (
|
||||
'terra_msg_event_model',
|
||||
'terra-5_msg_event_model'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :block_id :: bigint AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :chain_id :: STRING AS chain_id,
|
||||
COALESCE(
|
||||
t.value :txhash :: STRING,
|
||||
-- Pre Columbus-5: tx_id
|
||||
-- Post Columbus-4: txhash
|
||||
t.value :tx_id :: STRING
|
||||
) AS tx_id,
|
||||
t.value :tx_module :: STRING AS tx_module,
|
||||
t.value :tx_status :: STRING AS tx_status,
|
||||
t.value :tx_type :: STRING AS tx_type,
|
||||
t.value :msg_index :: INTEGER AS msg_index,
|
||||
t.value :msg_type :: STRING AS msg_type,
|
||||
t.value :msg_module :: STRING AS msg_module,
|
||||
t.value :event_type :: STRING AS event_type,
|
||||
t.value :event_index :: INTEGER AS event_index,
|
||||
t.value :event_attributes :: OBJECT AS event_attributes,
|
||||
t.value :event_attributes_actions :: OBJECT AS event_attributes_actions
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
WHERE t.value :event_attributes_actions :: OBJECT IS NOT NULL
|
||||
60
models/bronze/classic/bronze__classic_msgs.sql
Normal file
60
models/bronze/classic/bronze__classic_msgs.sql
Normal file
@ -0,0 +1,60 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, tx_id, msg_index)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_msgs'],
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content :model :name :: STRING IN (
|
||||
'terra_msg_model',
|
||||
'terra-5_msg_model'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :block_id :: bigint AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :chain_id :: STRING AS chain_id,
|
||||
COALESCE(
|
||||
t.value :txhash :: STRING,
|
||||
-- Pre Columbus-5: tx_id
|
||||
-- Post Columbus-4: txhash
|
||||
t.value :tx_id :: STRING
|
||||
) AS tx_id,
|
||||
t.value :tx_type :: STRING AS tx_type,
|
||||
t.value :tx_status :: STRING AS tx_status,
|
||||
t.value :tx_module :: STRING AS tx_module,
|
||||
t.value :tx_memo ::STRING AS tx_memo,
|
||||
t.value :msg_index :: INTEGER AS msg_index,
|
||||
t.value :msg_type :: STRING AS msg_type,
|
||||
t.value :msg_module :: STRING AS msg_module,
|
||||
t.value :msg_value :: variant AS msg_value
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
169
models/bronze/classic/bronze__classic_nft_metadata.sql
Normal file
169
models/bronze/classic/bronze__classic_nft_metadata.sql
Normal file
@ -0,0 +1,169 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', contract_address, token_id)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
tags = ['snowflake', 'classic', 'bronze__classic_nft_metadata']
|
||||
) }}
|
||||
|
||||
WITH galactic_punks AS (
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_rest_proxy_1507016047'
|
||||
) }}
|
||||
WHERE
|
||||
record_metadata :key :: STRING IN (
|
||||
'"testing-1635197180"'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND (
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP :: DATE >= (
|
||||
SELECT
|
||||
DATEADD('day', -10, MAX(system_created_at :: DATE))
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
'terra' AS blockchain,
|
||||
NULL AS commission_rate,
|
||||
VALUE :collection_addr :: STRING AS contract_address,
|
||||
'Galactic Punks' AS contract_name,
|
||||
NULL AS created_at_block_id,
|
||||
VALUE :created_at :: TIMESTAMP AS created_at_timestamp,
|
||||
NULL AS created_at_tx_id,
|
||||
NULL AS creator_address,
|
||||
NULL AS creator_name,
|
||||
VALUE :src :: STRING AS image_url,
|
||||
'Galactic Punks' AS project_name,
|
||||
VALUE :token_id :: STRING AS token_id,
|
||||
PARSE_JSON(
|
||||
CONCAT(
|
||||
'{"traits": ',
|
||||
PARSE_JSON(
|
||||
SPLIT_PART(SPLIT_PART(VALUE :attributes :: STRING, '[', 2), ']', 1)
|
||||
),
|
||||
', "additional_metadata": ',
|
||||
PARSE_JSON(
|
||||
VALUE :additional_metadata
|
||||
),
|
||||
'}'
|
||||
)
|
||||
) AS token_metadata,
|
||||
NULL AS token_metadata_uri,
|
||||
VALUE :name AS token_name
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN (
|
||||
input => record_content
|
||||
) t
|
||||
),
|
||||
|
||||
terra_nft_metadata AS (
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'shared',
|
||||
'prod_nft_metadata_uploads_1828572827'
|
||||
) }}
|
||||
WHERE
|
||||
SPLIT(
|
||||
record_content :model :sinks [0] :destination :: STRING,
|
||||
'.'
|
||||
) [2] :: STRING = 'nft_metadata'
|
||||
AND record_content :model :blockchain :: STRING = 'terra'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND (
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP :: DATE >= (
|
||||
SELECT
|
||||
DATEADD('day', -10, MAX(system_created_at :: DATE))
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
)
|
||||
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
'terra' AS blockchain,
|
||||
t.value :commission_rate :: FLOAT AS commission_rate,
|
||||
t.value :contract_address :: STRING AS contract_address,
|
||||
t.value :contract_name :: STRING AS contract_name,
|
||||
t.value :created_at_block_id :: bigint AS created_at_block_id,
|
||||
t.value :created_at_timestamp :: TIMESTAMP AS created_at_timestamp,
|
||||
t.value :created_at_tx_id :: STRING AS created_at_tx_id,
|
||||
t.value :creator_address :: STRING AS creator_address,
|
||||
t.value :creator_name :: STRING AS creator_name,
|
||||
t.value :image_url :: STRING AS image_url,
|
||||
t.value :project_name :: STRING AS project_name,
|
||||
t.value :token_id :: STRING AS token_id,
|
||||
t.value :token_metadata :: OBJECT AS token_metadata,
|
||||
t.value :token_metadata_uri :: STRING AS token_metadata_uri,
|
||||
t.value :token_name :: STRING AS token_name,*
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN (
|
||||
input => record_content:results
|
||||
) t
|
||||
)
|
||||
|
||||
SELECT
|
||||
system_created_at,
|
||||
blockchain,
|
||||
commission_rate,
|
||||
contract_address,
|
||||
contract_name,
|
||||
created_at_block_id,
|
||||
created_at_timestamp,
|
||||
created_at_tx_id,
|
||||
creator_address,
|
||||
creator_name,
|
||||
image_url,
|
||||
project_name,
|
||||
token_id,
|
||||
token_metadata,
|
||||
token_metadata_uri,
|
||||
token_name
|
||||
|
||||
FROM terra_nft_metadata
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
system_created_at,
|
||||
blockchain,
|
||||
commission_rate,
|
||||
contract_address,
|
||||
contract_name,
|
||||
created_at_block_id,
|
||||
created_at_timestamp,
|
||||
created_at_tx_id,
|
||||
creator_address,
|
||||
creator_name,
|
||||
image_url,
|
||||
project_name,
|
||||
token_id,
|
||||
token_metadata,
|
||||
token_metadata_uri,
|
||||
token_name
|
||||
|
||||
FROM galactic_punks
|
||||
47
models/bronze/classic/bronze__classic_synthetic_balances.sql
Normal file
47
models/bronze/classic/bronze__classic_synthetic_balances.sql
Normal file
@ -0,0 +1,47 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', block_timestamp, chain_id, block_id, inputs)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_balances']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content:model:class in ('terra.balances.terra_synthetic_balances_model.TerraSyntheticBalancesModel',
|
||||
'terra.balances.terra_synthetic_balances_model.Terra5SyntheticBalancesModel')
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
)
|
||||
|
||||
SELECT
|
||||
(record_metadata :CreateTime :: INT / 1000) :: TIMESTAMP AS _system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :block_id :: bigint AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :chain_id :: STRING AS chain_id,
|
||||
t.value :function_name :: STRING AS function_name,
|
||||
t.value :inputs :: STRING AS inputs,
|
||||
t.value :project_id :: STRING AS project_id,
|
||||
t.value :project_name :: STRING AS project_name,
|
||||
t.value :value_numeric :: INTEGER AS value_numeric,
|
||||
t.value :value_obj :: OBJECT AS value_obj
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(input => record_content :results) t
|
||||
@ -0,0 +1,47 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, contract_address)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terraswap', 'pool_reserves']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
r.value :chain_id :: STRING AS chain_id,
|
||||
r.value :block_id :: INT AS block_id,
|
||||
r.value :blockchain :: STRING AS blockchain,
|
||||
r.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
r.value :contract_address :: STRING AS contract_address,
|
||||
r.value :value_obj :total_share :: INTEGER AS total_share,
|
||||
r.value :value_obj :asset_1 :: STRING AS token_0_currency,
|
||||
r.value :value_obj :asset_1_value :: INTEGER AS token_0_amount,
|
||||
r.value :value_obj :asset_2 :: STRING AS token_1_currency,
|
||||
r.value :value_obj :asset_2_value :: INTEGER AS token_1_amount
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }},
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) AS r
|
||||
WHERE
|
||||
(
|
||||
record_content :model.name = 'terra-5_terraswap_pool_reserves'
|
||||
OR record_content :model.name = 'terra-5_terraswap_pool_reserves_bison'
|
||||
OR record_content :model.name = 'terra-5_terraswap_pool_reserves_backfill'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND (
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP :: DATE >= (
|
||||
SELECT
|
||||
DATEADD('day', -1, MAX(system_created_at :: DATE))
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
68
models/bronze/classic/bronze__classic_transactions.sql
Normal file
68
models/bronze/classic/bronze__classic_transactions.sql
Normal file
@ -0,0 +1,68 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, tx_id)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_transactions']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
(
|
||||
record_content :model :name :: STRING = 'terra_tx_model'
|
||||
AND record_content:model.run_id = 'v2022.03.02.0'
|
||||
)
|
||||
OR
|
||||
(
|
||||
record_content :model :name :: STRING = 'terra-5_tx_model'
|
||||
AND record_content:model.run_id = 'v2022.01.14.0'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :block_id :: bigint AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :chain_id :: STRING AS chain_id,
|
||||
t.value :codespace :: STRING AS codespace,
|
||||
COALESCE(
|
||||
t.value :txhash :: STRING,
|
||||
-- Pre Columbus-5: tx_id
|
||||
-- Post Columbus-4: txhash
|
||||
t.value :tx_id :: STRING
|
||||
) AS tx_id,
|
||||
t.value :tx_from as tx_from,
|
||||
t.value :tx_to as tx_to,
|
||||
t.value :tx_type :: STRING AS tx_type,
|
||||
t.value :tx_module :: STRING AS tx_module,
|
||||
t.value :tx_status :: STRING AS tx_status,
|
||||
t.value :tx_status_msg :: STRING AS tx_status_msg,
|
||||
t.value :tx_code :: INTEGER AS tx_code,
|
||||
t.value :fee :: ARRAY AS fee,
|
||||
t.value :gas_wanted :: DOUBLE AS gas_wanted,
|
||||
t.value :gas_used :: DOUBLE AS gas_used
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
50
models/bronze/classic/bronze__classic_transitions.sql
Normal file
50
models/bronze/classic/bronze__classic_transitions.sql
Normal file
@ -0,0 +1,50 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "CONCAT_WS('-', chain_id, block_id, transition_type, index, event)",
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
tags = ['snowflake', 'classic', 'terra_transitions']
|
||||
) }}
|
||||
|
||||
WITH base_tables AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_terra_sink_645110886'
|
||||
) }}
|
||||
WHERE
|
||||
record_content :model :name :: STRING IN (
|
||||
'terra_transition_model',
|
||||
'terra-5_transition_model'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
(
|
||||
record_metadata :CreateTime :: INT / 1000
|
||||
) :: TIMESTAMP AS system_created_at,
|
||||
_inserted_timestamp,
|
||||
t.value :blockchain :: STRING AS blockchain,
|
||||
t.value :block_id :: bigint AS block_id,
|
||||
t.value :block_timestamp :: TIMESTAMP AS block_timestamp,
|
||||
t.value :chain_id :: STRING AS chain_id,
|
||||
t.value :event :: STRING AS event,
|
||||
t.value :index :: INTEGER AS INDEX,
|
||||
t.value :transition_type :: STRING AS transition_type,
|
||||
t.value :attributes :: OBJECT AS event_attributes
|
||||
FROM
|
||||
base_tables,
|
||||
LATERAL FLATTEN(
|
||||
input => record_content :results
|
||||
) t
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ASTROPORT',
|
||||
'PURPOSE': 'DEX' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'astroport',
|
||||
'pool_reserves'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'BALANCES' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'daily_balances'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra_sv',
|
||||
'labels'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'NFT' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'nft_metadata'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'oracle_prices'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'tax_rate'
|
||||
) }}
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'TERRASWAP',
|
||||
'PURPOSE': 'DEX' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terraswap',
|
||||
'pool_reserves'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'validator_labels'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'validator_voting_power'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'AIRDROP' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'airdrop_claims'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'bonds'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'borrows'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'burns'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'collateral'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'deposits'
|
||||
) }}
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR',
|
||||
'PURPOSE': 'STAKING' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'gov_staking'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'gov_submit_proposal'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'gov_vote'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'liquidations'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'redeem'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'repay'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'anchor',
|
||||
'reward_claims'
|
||||
) }}
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ASTROPORT',
|
||||
'PURPOSE': 'DEX, SWAPS' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'astroport',
|
||||
'swaps'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'GOVERNANCE' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'gov_submit_proposal'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'GOVERNANCE' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'gov_vote'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'reward'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'STAKING' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'staking'
|
||||
) }}
|
||||
@ -1,13 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'DEX, SWAPS' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'swaps'
|
||||
) }}
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'TERRASWAP',
|
||||
'PURPOSE': 'DEX' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terraswap',
|
||||
'lp_actions'
|
||||
) }}
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'TERRASWAP',
|
||||
'PURPOSE': 'DEX' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terraswap',
|
||||
'lp_stake'
|
||||
) }}
|
||||
@ -1,14 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'TERRASWAP',
|
||||
'PURPOSE': 'DEX, SWAPS' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terraswap',
|
||||
'swaps'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra',
|
||||
'transfers'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra_sv',
|
||||
'blocks'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra_sv',
|
||||
'msg_events'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra_sv',
|
||||
'msgs'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra_sv',
|
||||
'transactions'
|
||||
) }}
|
||||
@ -1,12 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true'
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'terra_sv',
|
||||
'transitions'
|
||||
) }}
|
||||
5
models/descriptions/liquidity_pool_shares.md
Normal file
5
models/descriptions/liquidity_pool_shares.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs liquidity_pool_shares %}
|
||||
|
||||
The total amount of shares in a pool.
|
||||
|
||||
{% enddocs %}
|
||||
21
models/gold/classic/classic__dim_astroport_pool_reserves.sql
Normal file
21
models/gold/classic/classic__dim_astroport_pool_reserves.sql
Normal file
@ -0,0 +1,21 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ASTROPORT',
|
||||
'PURPOSE': 'DEX' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
'terra' as blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
contract_address,
|
||||
total_share / pow(10,6) AS total_share,
|
||||
token_0_currency,
|
||||
token_0_amount / pow(10,6) AS token_0_amount,
|
||||
token_1_currency,
|
||||
token_1_amount / pow(10,6) AS token_1_amount
|
||||
FROM
|
||||
{{ ref('silver_classic__astroport_pool_reserves') }}
|
||||
26
models/gold/classic/classic__dim_astroport_pool_reserves.yml
Normal file
26
models/gold/classic/classic__dim_astroport_pool_reserves.yml
Normal file
@ -0,0 +1,26 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_astroport_pool_reserves
|
||||
descriptions: |-
|
||||
This table provides block by block pool reserve information including total pool shares, pool currencies, and token amounts in Astroport pools.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: CHAIN_ID
|
||||
description: "{{ doc('chain_id') }}"
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: "{{ doc('liquidity_pool_address') }}"
|
||||
- name: TOTAL_SHARE
|
||||
description: "{{ doc('liquidity_pool_shares') }}"
|
||||
- name: TOKEN_0_CURRENCY
|
||||
description: Token 0 currency
|
||||
- name: TOKEN_0_AMOUNT
|
||||
description: Token 0 amount in pool
|
||||
- name: TOKEN_1_CURRENCY
|
||||
description: Token 1 currency
|
||||
- name: TOKEN_1_AMOUNT
|
||||
description: Token 1 amount in pool
|
||||
40
models/gold/classic/classic__dim_contract_metadata.sql
Normal file
40
models/gold/classic/classic__dim_contract_metadata.sql
Normal file
@ -0,0 +1,40 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['snowflake', 'classic', 'terra', 'contract_metadata']
|
||||
) }}
|
||||
|
||||
WITH dex_contracts AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
contract_address,
|
||||
decimals,
|
||||
contract_name,
|
||||
symbol,
|
||||
FALSE AS is_wormhole
|
||||
FROM {{ ref('silver_classic__dex_contracts') }}
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
contract_address,
|
||||
decimals,
|
||||
contract_name,
|
||||
symbol,
|
||||
is_wormhole
|
||||
FROM {{ ref('silver_classic__contract_metadata') }}
|
||||
WHERE contract_address NOT IN (SELECT contract_address FROM dex_contracts)
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
contract_address,
|
||||
decimals,
|
||||
contract_name,
|
||||
symbol,
|
||||
is_wormhole
|
||||
FROM dex_contracts
|
||||
21
models/gold/classic/classic__dim_contract_metadata.yml
Normal file
21
models/gold/classic/classic__dim_contract_metadata.yml
Normal file
@ -0,0 +1,21 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_contract_metadata
|
||||
descriptions: |-
|
||||
This table records on-chain contract metadata from contract creation events.
|
||||
columns:
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: TX_ID
|
||||
description: "{{ doc('tx_id') }}"
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: "{{ doc('address') }}"
|
||||
- name: DECIMALS
|
||||
description: "{{ doc('decimal') }}"
|
||||
- name: CONTRACT_NAME
|
||||
description: "{{ doc('label') }}"
|
||||
- name: SYMBOL
|
||||
description: "{{ doc('symbol') }}"
|
||||
- name: IS_WORMHOLE
|
||||
description: Wormhole tokens = TRUE, else FALSE.
|
||||
|
||||
82
models/gold/classic/classic__dim_daily_balances.sql
Normal file
82
models/gold/classic/classic__dim_daily_balances.sql
Normal file
@ -0,0 +1,82 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'BALANCES' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
p.symbol,
|
||||
l.address_name,
|
||||
DATE_TRUNC(
|
||||
'day',
|
||||
block_timestamp
|
||||
) AS DAY,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }} p
|
||||
LEFT JOIN {{ ref('classic__dim_labels') }} l
|
||||
on p.symbol = l.address
|
||||
where 1=1
|
||||
GROUP BY
|
||||
p.symbol,
|
||||
DAY,
|
||||
l.address_name
|
||||
)
|
||||
|
||||
SELECT
|
||||
DATE,
|
||||
b.address,
|
||||
address_labels.l1_label AS address_label_type,
|
||||
address_labels.l2_label AS address_label_subtype,
|
||||
address_labels.project_name AS address_label,
|
||||
address_labels.address_name AS address_name,
|
||||
balance,
|
||||
balance * p.price AS balance_usd,
|
||||
b.balance_type,
|
||||
b.is_native,
|
||||
currency
|
||||
FROM
|
||||
{{ ref('silver_classic__daily_balances') }} b
|
||||
LEFT OUTER JOIN prices p
|
||||
ON p.symbol = case when b.currency = 'USD' then 'UST'
|
||||
when len(b.currency) = 3 then upper(concat(substring(b.currency,1,2),'T'))
|
||||
when substring(b.currency,1,1) = 'U' then upper(concat(substring(b.currency,2,2),'T'))
|
||||
else b.currency end
|
||||
AND p.day = b.date
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS address_labels
|
||||
ON b.address = address_labels.address AND address_labels.blockchain = 'terra' AND address_labels.creator = 'flipside'
|
||||
WHERE
|
||||
lower(b.currency) not like 'ibc%'
|
||||
and b.currency <> 'UNOK'
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
DATE,
|
||||
b.address,
|
||||
address_labels.l1_label AS address_label_type,
|
||||
address_labels.l2_label AS address_label_subtype,
|
||||
address_labels.project_name AS address_label,
|
||||
address_labels.address_name AS address_name,
|
||||
balance,
|
||||
CASE
|
||||
WHEN p.price * balance IS NULL
|
||||
THEN (last_value(p.price ignore nulls) over (partition by currency order by DATE asc rows between unbounded preceding and current row)) * balance
|
||||
ELSE balance * p.price
|
||||
END AS balance_usd,
|
||||
b.balance_type,
|
||||
b.is_native,
|
||||
currency
|
||||
FROM {{ ref('silver_classic__block_synthetic_balances') }} b
|
||||
|
||||
LEFT OUTER JOIN prices p
|
||||
ON p.symbol = currency
|
||||
AND p.day = b.date
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS address_labels
|
||||
ON b.address = address_labels.address
|
||||
AND address_labels.blockchain = 'terra'
|
||||
AND address_labels.creator = 'flipside'
|
||||
29
models/gold/classic/classic__dim_daily_balances.yml
Normal file
29
models/gold/classic/classic__dim_daily_balances.yml
Normal file
@ -0,0 +1,29 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_daily_balances
|
||||
descriptions: |-
|
||||
This table records daily balances of native tokens and select CW20 tokens for all addresses on the Terra blockchain.
|
||||
columns:
|
||||
- name: DATE
|
||||
description: Data balance was recorded.
|
||||
- name: ADDRESS
|
||||
description: "{{ doc('address')}}"
|
||||
- name: ADDRESS_LABEL_TYPE
|
||||
description: "{{ doc('label_type') }}"
|
||||
- name: ADDRESS_LABEL_SUBTYPE
|
||||
description: "{{ doc('label_subtype') }}"
|
||||
- name: ADDRESS_LABEL
|
||||
description: "{{ doc('project_name') }}"
|
||||
- name: ADDRESS_NAME
|
||||
description: "{{ doc('label') }}"
|
||||
- name: BALANCE
|
||||
description: The token amount.
|
||||
- name: BALANCE_TYPE
|
||||
description: Balance type, liquid or staked.
|
||||
- name: BALANCE_USD
|
||||
description: The token amount, in USD.
|
||||
- name: CURRENCY
|
||||
description: "{{ doc('symbol')}}"
|
||||
- name: IS_NATIVE
|
||||
description: Native tokens = TRUE, CW20 tokens = FALSE
|
||||
|
||||
10
models/gold/classic/classic__dim_labels.sql
Normal file
10
models/gold/classic/classic__dim_labels.sql
Normal file
@ -0,0 +1,10 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ref('terra_sv__labels')}}
|
||||
22
models/gold/classic/classic__dim_labels.yml
Normal file
22
models/gold/classic/classic__dim_labels.yml
Normal file
@ -0,0 +1,22 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: classic__dim_labels
|
||||
descriptions: |-
|
||||
This table contains Terra blockchain's list of addresses and their labels.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: LABEL
|
||||
description: "{{ doc('project_name') }}"
|
||||
- name: ADDRESS
|
||||
description: "{{ doc('address') }}"
|
||||
- name: CREATOR
|
||||
description: "{{ doc('creator') }}"
|
||||
- name: LABEL_TYPE
|
||||
description: "{{ doc('label_type') }}"
|
||||
- name: LABEL_SUBTYPE
|
||||
description: "{{ doc('label_subtype') }}"
|
||||
- name: ADDRESS_NAME
|
||||
description: "{{ doc('label') }}"
|
||||
|
||||
25
models/gold/classic/classic__dim_nft_metadata.sql
Normal file
25
models/gold/classic/classic__dim_nft_metadata.sql
Normal file
@ -0,0 +1,25 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'NFT' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
contract_address,
|
||||
contract_name,
|
||||
created_at_timestamp,
|
||||
created_at_tx_id,
|
||||
creator_address,
|
||||
creator_name,
|
||||
image_url,
|
||||
project_name,
|
||||
token_id,
|
||||
token_metadata,
|
||||
token_metadata_uri,
|
||||
token_name
|
||||
FROM
|
||||
{{ ref('silver_classic__nft_metadata') }}
|
||||
WHERE
|
||||
blockchain = 'terra'
|
||||
36
models/gold/classic/classic__dim_nft_metadata.yml
Normal file
36
models/gold/classic/classic__dim_nft_metadata.yml
Normal file
@ -0,0 +1,36 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_nft_metadata
|
||||
descriptions: |-
|
||||
This table contains metadata for popular NFTs on the Terra blockchain.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: commission_rate
|
||||
description: Commission fee when an NFT is sold.
|
||||
- name: contract_address
|
||||
description: "{{ doc('contract_address') }}"
|
||||
- name: contract_name
|
||||
description: "{{ doc('label') }}"
|
||||
- name: created_at_block_id
|
||||
description: "{{ doc('block_id') }}"
|
||||
- name: created_at_timestamp
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
- name: created_at_tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
- name: creator_address
|
||||
description: "{{ doc('address') }}"
|
||||
- name: creator_name
|
||||
description: "{{ doc('label') }}"
|
||||
- name: image_url
|
||||
description: URL of the image.
|
||||
- name: project_name
|
||||
description: "{{ doc('project_name') }}"
|
||||
- name: token_id
|
||||
description: "{{ doc('token_id') }}"
|
||||
- name: token_metadata
|
||||
description: The token metadata.
|
||||
- name: token_metadata_uri
|
||||
description: The uri that will return the address where the metadata of this specific token is stored.
|
||||
- name: token_name
|
||||
description: "{{ doc('label') }}"
|
||||
204
models/gold/classic/classic__dim_oracle_prices.sql
Normal file
204
models/gold/classic/classic__dim_oracle_prices.sql
Normal file
@ -0,0 +1,204 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic']
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC('hour',recorded_at) AS block_timestamp,
|
||||
symbol AS currency,
|
||||
AVG(price) AS price
|
||||
FROM
|
||||
{{ source(
|
||||
'shared',
|
||||
'legacy_prices'
|
||||
) }}
|
||||
WHERE
|
||||
asset_id = '4172'
|
||||
AND provider is not null
|
||||
GROUP BY
|
||||
1,
|
||||
2
|
||||
),
|
||||
|
||||
other_prices AS (
|
||||
SELECT
|
||||
DATE_TRUNC('hour', recorded_at) AS block_timestamp,
|
||||
symbol AS currency,
|
||||
AVG(price) AS price
|
||||
FROM
|
||||
{{ source('shared','legacy_prices') }}
|
||||
WHERE
|
||||
asset_id IN(
|
||||
'7857',
|
||||
'8857'
|
||||
)
|
||||
GROUP BY
|
||||
1,
|
||||
2
|
||||
),
|
||||
|
||||
luna_rate AS (
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_timestamp,
|
||||
block_id,
|
||||
REGEXP_REPLACE(event_attributes :denom :: STRING,'\"','') AS currency,
|
||||
event_attributes :exchange_rate :: FLOAT AS exchange_rate
|
||||
FROM
|
||||
{{ ref('silver_classic__transitions') }}
|
||||
WHERE
|
||||
event = 'exchange_rate_update'
|
||||
|
||||
),
|
||||
|
||||
|
||||
polymine AS (
|
||||
|
||||
SELECT
|
||||
'terra' as blockchain,
|
||||
DATE_TRUNC('minute', recorded_at) AS block_timestamp,
|
||||
'terra1kcthelkax4j9x8d3ny6sdag0qmxxynl3qtcrpy' AS currency,
|
||||
symbol,
|
||||
AVG(p.price) AS price,
|
||||
'coinmarketcap' as source
|
||||
FROM {{ source('shared','legacy_prices') }} p
|
||||
WHERE asset_id IN('pylon-protocol',
|
||||
'10767')
|
||||
GROUP BY 1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
6
|
||||
|
||||
),
|
||||
|
||||
feed_prices AS (
|
||||
SELECT
|
||||
m.blockchain,
|
||||
date_trunc('hour', m.block_timestamp) as block_timestamp,
|
||||
f.value[0] ::STRING AS currency,
|
||||
AVG(f.value[1] ::FLOAT) AS price_usd
|
||||
FROM {{ ref('silver_classic__msgs') }} m,
|
||||
lateral flatten (input => msg_value :execute_msg :feed_price :prices) f
|
||||
WHERE msg_value :execute_msg :feed_price IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
GROUP BY 1,2,3
|
||||
)
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
l.block_timestamp,
|
||||
l.currency,
|
||||
CASE
|
||||
WHEN l.currency = 'usgd' THEN 'SGT'
|
||||
WHEN l.currency = 'uusd' THEN 'UST'
|
||||
WHEN l.currency = 'ukrw' THEN 'KRT'
|
||||
WHEN l.currency = 'unok' THEN 'NOT'
|
||||
WHEN l.currency = 'ucny' THEN 'CNT'
|
||||
WHEN l.currency = 'uinr' THEN 'INT'
|
||||
WHEN l.currency = 'ueur' THEN 'EUT'
|
||||
WHEN l.currency = 'udkk' THEN 'DKT'
|
||||
WHEN l.currency = 'uhkd' THEN 'HKT'
|
||||
WHEN l.currency = 'usek' THEN 'SET'
|
||||
WHEN l.currency = 'uthb' THEN 'THT'
|
||||
WHEN l.currency = 'umnt' THEN 'MNT'
|
||||
WHEN l.currency = 'ucad' THEN 'CAT'
|
||||
WHEN l.currency = 'ugbp' THEN 'GBT'
|
||||
WHEN l.currency = 'ujpy' THEN 'JPT'
|
||||
WHEN l.currency = 'usdr' THEN 'SDT'
|
||||
WHEN l.currency = 'uchf' THEN 'CHT'
|
||||
WHEN l.currency = 'uaud' THEN 'AUT'
|
||||
WHEN l.currency = 'uidr' THEN 'IDT'
|
||||
WHEN l.currency = 'uphp' THEN 'PHT'
|
||||
WHEN l.currency = 'utwd' THEN 'TWT'
|
||||
WHEN l.currency = 'umyr' THEN 'MYT'
|
||||
ELSE l.currency
|
||||
END AS symbol,
|
||||
exchange_rate AS luna_exchange_rate,
|
||||
CASE
|
||||
WHEN (price/exchange_rate) IS NULL
|
||||
THEN (last_value(price ignore nulls) over (partition by symbol order by l.block_timestamp asc rows between unbounded preceding and current row))/exchange_rate
|
||||
else price/exchange_rate
|
||||
END AS price_usd,
|
||||
'oracle' AS source
|
||||
FROM
|
||||
luna_rate l
|
||||
|
||||
LEFT OUTER JOIN prices p
|
||||
ON DATE_TRUNC('hour',l.block_timestamp) = p.block_timestamp
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
'terra' AS blockchain,
|
||||
block_timestamp,
|
||||
'uluna' AS currency,
|
||||
'LUNA' AS symbol,
|
||||
1 AS luna_exchange_rate,
|
||||
price AS price_usd,
|
||||
'coinmarketcap' AS source
|
||||
FROM prices
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
'terra' AS blockchain,
|
||||
o.block_timestamp,
|
||||
CASE
|
||||
WHEN o.currency = 'MIR' THEN 'terra15gwkyepfc6xgca5t5zefzwy42uts8l2m4g40k6'
|
||||
WHEN o.currency = 'ANC' THEN 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76'
|
||||
ELSE NULL
|
||||
END AS currency,
|
||||
o.currency AS symbol,
|
||||
x.price / o.price AS luna_exchange_rate,
|
||||
o.price AS price_usd,
|
||||
'coinmarketcap' AS source
|
||||
FROM
|
||||
other_prices o
|
||||
|
||||
LEFT OUTER JOIN prices x
|
||||
ON DATE_TRUNC('hour',o.block_timestamp) = x.block_timestamp
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
ee.blockchain,
|
||||
ee.block_timestamp,
|
||||
ee.currency,
|
||||
l.address_name AS symbol,
|
||||
CASE WHEN ee.currency = 'terra1z3e2e4jpk4n0xzzwlkgcfvc95pc5ldq0xcny58'
|
||||
THEN pp.price / (ee.price_usd * POW(10,2))
|
||||
ELSE pp.price / ee.price_usd END AS luna_exchange_rate,
|
||||
CASE WHEN ee.currency = 'terra1z3e2e4jpk4n0xzzwlkgcfvc95pc5ldq0xcny58'
|
||||
THEN ee.price_usd * POW(10,2)
|
||||
ELSE ee.price_usd END AS price_usd,
|
||||
'oracle' AS source
|
||||
FROM feed_prices ee
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON ee.currency = l.address
|
||||
AND l.blockchain = 'terra'
|
||||
AND l.creator = 'flipside'
|
||||
|
||||
LEFT OUTER JOIN prices pp
|
||||
ON DATE_TRUNC('hour', ee.block_timestamp) = pp.block_timestamp
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
p.blockchain,
|
||||
p.block_timestamp,
|
||||
p.currency,
|
||||
p.symbol,
|
||||
l.price/ p.price as luna_exchange_rate,
|
||||
p.price AS price_usd,
|
||||
p.source
|
||||
FROM polymine p
|
||||
|
||||
LEFT OUTER JOIN prices l
|
||||
ON date_trunc('hour', p.block_timestamp) = l.block_timestamp
|
||||
|
||||
20
models/gold/classic/classic__dim_oracle_prices.yml
Normal file
20
models/gold/classic/classic__dim_oracle_prices.yml
Normal file
@ -0,0 +1,20 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_oracle_prices
|
||||
descriptions: |-
|
||||
This table records token prices per block_timestamp. Includes prices from two sources: 1. Coinmarketcap 2. Oracle: On-chain messages and transitions.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: CURRENCY
|
||||
description: "{{ doc('address')}}"
|
||||
- name: LUNA_EXCHANGE_RATE
|
||||
description: The exchange ratio to change this token for LUNA.
|
||||
- name: PRICE_USD
|
||||
description: The price at this timestamp, in USD.
|
||||
- name: SOURCE
|
||||
description: The source of the pricing data.
|
||||
- name: SYMBOL
|
||||
description: "{{ doc('symbol')}}"
|
||||
17
models/gold/classic/classic__dim_tax_rate.sql
Normal file
17
models/gold/classic/classic__dim_tax_rate.sql
Normal file
@ -0,0 +1,17 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
chain_id AS blockchain,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
tax_rate
|
||||
FROM
|
||||
{{ ref(
|
||||
'silver_classic__tax_rate'
|
||||
) }}
|
||||
WHERE
|
||||
1 = 1
|
||||
14
models/gold/classic/classic__dim_tax_rate.yml
Normal file
14
models/gold/classic/classic__dim_tax_rate.yml
Normal file
@ -0,0 +1,14 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_tax_rate
|
||||
descriptions: |-
|
||||
This table records the tax ratio for each block. Note: In January 2022 the tax rate on Terra was lowered to 0%.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: BLOCK_NUMBER
|
||||
description: "{{ doc('block_id')}}"
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: TAX_RATE
|
||||
description: The tax ratio for this block.
|
||||
22
models/gold/classic/classic__dim_terraswap_pool_reserves.sql
Normal file
22
models/gold/classic/classic__dim_terraswap_pool_reserves.sql
Normal file
@ -0,0 +1,22 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'TERRASWAP',
|
||||
'PURPOSE': 'DEX' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
'terra' as blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
contract_address,
|
||||
total_share / pow(10,6) AS total_share,
|
||||
token_0_currency,
|
||||
token_0_amount / pow(10,6) AS token_0_amount,
|
||||
token_1_currency,
|
||||
token_1_amount / pow(10,6) AS token_1_amount
|
||||
FROM
|
||||
{{ ref('silver_classic__terraswap_pool_reserves') }}
|
||||
|
||||
26
models/gold/classic/classic__dim_terraswap_pool_reserves.yml
Normal file
26
models/gold/classic/classic__dim_terraswap_pool_reserves.yml
Normal file
@ -0,0 +1,26 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_terraswap_pool_reserves
|
||||
descriptions: |-
|
||||
This table provides block by block pool reserve information including total pool shares, pool currencies, and token amounts in Terraswap pools.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: CHAIN_ID
|
||||
description: "{{ doc('chain_id') }}"
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: "{{ doc('liquidity_pool_address') }}"
|
||||
- name: TOTAL_SHARE
|
||||
description: "{{ doc('liquidity_pool_shares') }}"
|
||||
- name: TOKEN_0_CURRENCY
|
||||
description: Token 0 currency
|
||||
- name: TOKEN_0_AMOUNT
|
||||
description: Token 0 amount in pool
|
||||
- name: TOKEN_1_CURRENCY
|
||||
description: Token 1 currency
|
||||
- name: TOKEN_1_AMOUNT
|
||||
description: Token 1 amount in pool
|
||||
44
models/gold/classic/classic__dim_validator_labels.sql
Normal file
44
models/gold/classic/classic__dim_validator_labels.sql
Normal file
@ -0,0 +1,44 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic']
|
||||
) }}
|
||||
|
||||
WITH base AS (
|
||||
|
||||
SELECT
|
||||
project_name AS label,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN address_name = 'operator_address' THEN address
|
||||
ELSE NULL
|
||||
END
|
||||
) AS operator_address,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN address_name = 'delegator_address' THEN address
|
||||
ELSE NULL
|
||||
END
|
||||
) AS delegator_address,
|
||||
MAX(
|
||||
CASE
|
||||
WHEN address_name = 'vp_address' THEN address
|
||||
ELSE NULL
|
||||
END
|
||||
) AS vp_address
|
||||
FROM
|
||||
{{ ref('silver_classic__address_labels') }}
|
||||
WHERE
|
||||
blockchain = 'terra'
|
||||
AND l1_label = 'operator'
|
||||
GROUP BY
|
||||
label
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
base
|
||||
WHERE
|
||||
operator_address IS NOT NULL
|
||||
OR delegator_address IS NOT NULL
|
||||
OR vp_address IS NOT NULL
|
||||
15
models/gold/classic/classic__dim_validator_labels.yml
Normal file
15
models/gold/classic/classic__dim_validator_labels.yml
Normal file
@ -0,0 +1,15 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_validator_labels
|
||||
descriptions: |-
|
||||
This table records labels for Validator addresses that show up on-chain. These individual addresses are matched based on the public_key of the Validator addresses.
|
||||
columns:
|
||||
- name: LABEL
|
||||
description: "{{ doc('project_name') }}"
|
||||
- name: operator_address
|
||||
description: The validator address (terravaloper).
|
||||
- name: delegator_address
|
||||
description: The delegator address of the Validator (terra).
|
||||
- name: vp_address
|
||||
description: The Validator address used for Voting Power (terravalcons).
|
||||
|
||||
21
models/gold/classic/classic__dim_validator_voting_power.sql
Normal file
21
models/gold/classic/classic__dim_validator_voting_power.sql
Normal file
@ -0,0 +1,21 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number AS block_id,
|
||||
block_timestamp,
|
||||
blockchain,
|
||||
address,
|
||||
voting_power
|
||||
FROM
|
||||
{{ source(
|
||||
'bronze',
|
||||
'classic_validator_voting_power'
|
||||
) }}
|
||||
|
||||
qualify(ROW_NUMBER() over (PARTITION BY block_id, address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
17
models/gold/classic/classic__dim_validator_voting_power.yml
Normal file
17
models/gold/classic/classic__dim_validator_voting_power.yml
Normal file
@ -0,0 +1,17 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__dim_validator_voting_power
|
||||
descriptions: |-
|
||||
This table records a validator’s voting power per block.
|
||||
columns:
|
||||
- name: ADDRESS
|
||||
description: The validator address (terravaloper).
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: VOTING_POWER
|
||||
description: Validator's voting power, at this block.
|
||||
|
||||
27
models/gold/classic/classic__ez_airdrop_claims.sql
Normal file
27
models/gold/classic/classic__ez_airdrop_claims.sql
Normal file
@ -0,0 +1,27 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'AIRDROP' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :execute_msg :claim :stage :: STRING AS airdrop_id,
|
||||
msg_value :sender :: STRING AS claimer,
|
||||
msg_value :execute_msg :claim :amount / pow(10,6) AS amount,
|
||||
msg_value :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM {{ ref('silver_classic__msgs') }} m
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :contract :: STRING = l.address
|
||||
AND l.blockchain = 'terra'
|
||||
AND l.creator = 'flipside'
|
||||
|
||||
WHERE msg_value :execute_msg :claim :amount IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
26
models/gold/classic/classic__ez_airdrop_claims.yml
Normal file
26
models/gold/classic/classic__ez_airdrop_claims.yml
Normal file
@ -0,0 +1,26 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_airdrop_claims
|
||||
description: |-
|
||||
This table contains all the transfers that occurred in the Terra2 blockchain.
|
||||
columns:
|
||||
- name: AIRDROP_ID
|
||||
description: Stage of airdrop being claimed.
|
||||
- name: TX_ID
|
||||
description: "{{ doc('tx_id') }}"
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id')}}"
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp')}}"
|
||||
- name: CHAIN_ID
|
||||
description: "{{ doc('chain_id') }}"
|
||||
- name: AMOUNT
|
||||
description: The amount of tokens claimed.
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: "{{ doc('address') }}"
|
||||
- name: CONTRACT_LABEL
|
||||
description: "{{ doc('label') }}"
|
||||
- name: CLAIMER
|
||||
description: "{{ doc('tx_sender') }}"
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
103
models/gold/classic/classic__ez_anchor_bonds.sql
Normal file
103
models/gold/classic/classic__ez_anchor_bonds.sql
Normal file
@ -0,0 +1,103 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
msgs AS (
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_index,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :coins [0] :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS bonded_amount,
|
||||
bonded_amount * price AS bonded_amount_usd,
|
||||
msg_value :coins [0] :denom :: STRING AS bonded_currency,
|
||||
msg_value :execute_msg :bond :validator :: STRING AS validator,
|
||||
msg_value :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND msg_value :coins [0] :denom :: STRING = o.currency
|
||||
WHERE
|
||||
msg_value :execute_msg :bond IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
events AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
event_attributes :"exchange_rate" / pow(
|
||||
10,
|
||||
6
|
||||
) AS minted_amount,
|
||||
minted_amount * price AS minted_amount_usd,
|
||||
event_attributes :"denom" :: STRING AS minted_currency
|
||||
FROM
|
||||
{{ ref('silver_classic__msg_events') }}
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND event_attributes :"denom" :: STRING = o.currency
|
||||
WHERE
|
||||
tx_id IN(
|
||||
SELECT
|
||||
tx_id
|
||||
FROM
|
||||
msgs
|
||||
)
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
)
|
||||
SELECT DISTINCT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
sender,
|
||||
bonded_amount,
|
||||
bonded_amount_usd,
|
||||
bonded_currency,
|
||||
msg_index,
|
||||
validator,
|
||||
COALESCE(contract_address, '') AS contract_address,
|
||||
COALESCE(contract_label, '') AS contract_label
|
||||
FROM
|
||||
msgs m
|
||||
JOIN events e
|
||||
ON m.tx_id = e.tx_id
|
||||
32
models/gold/classic/classic__ez_anchor_bonds.yml
Normal file
32
models/gold/classic/classic__ez_anchor_bonds.yml
Normal file
@ -0,0 +1,32 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_bonds
|
||||
descriptions: |-
|
||||
This table records bond actions on the Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
- name: BONDED_AMOUNT_USD
|
||||
description: the bonded amount in USD currency
|
||||
- name: BONDED_AMOUNT
|
||||
description: the bonded amount
|
||||
- name: BONDED_CURRENCY
|
||||
description: the bonded amount currency
|
||||
- name: MSG_INDEX
|
||||
description: Message index
|
||||
- name: VALIDATOR
|
||||
description: Validator that validated the bond transaction
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
96
models/gold/classic/classic__ez_anchor_borrows.sql
Normal file
96
models/gold/classic/classic__ez_anchor_borrows.sql
Normal file
@ -0,0 +1,96 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
)
|
||||
|
||||
SELECT DISTINCT *
|
||||
FROM (
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.chain_id,
|
||||
a.block_id,
|
||||
a.block_timestamp,
|
||||
a.tx_id,
|
||||
action_log :borrower::STRING AS sender,
|
||||
action_log :borrow_amount / POW(10,6) AS amount,
|
||||
amount * price AS amount_usd,
|
||||
'uusd' AS currency,
|
||||
action_contract_address AS contract_address,
|
||||
l.address_name AS contract_label,
|
||||
CASE WHEN
|
||||
msg_value :execute_msg :process_anchor_message IS NOT NULL
|
||||
THEN 'Wormhole'
|
||||
ELSE 'Terra'
|
||||
END AS source
|
||||
FROM
|
||||
{{ ref('silver_classic__event_actions') }} a
|
||||
LEFT JOIN {{ ref('silver_classic__msgs') }} m
|
||||
ON a.tx_id = m.tx_id AND a.msg_index = m.msg_index
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
a.block_timestamp
|
||||
) = o.hour
|
||||
AND 'uusd' = o.currency
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON action_contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
action_method = 'borrow_stable' -- Anchor Borrow
|
||||
AND action_contract_address = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' -- Anchor Market Contract
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :execute_msg :borrow_stable :borrow_amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
amount * price AS amount_usd,
|
||||
'uusd' AS currency,
|
||||
msg_value :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label,
|
||||
'Terra' AS source
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND 'uusd' = o.currency
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
msg_value :execute_msg :borrow_stable IS NOT NULL -- Anchor Borrow
|
||||
AND msg_value :contract :: STRING = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' -- Anchor Market Contract
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
)
|
||||
30
models/gold/classic/classic__ez_anchor_borrows.yml
Normal file
30
models/gold/classic/classic__ez_anchor_borrows.yml
Normal file
@ -0,0 +1,30 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_borrows
|
||||
descriptions: |-
|
||||
This table records borrowing transactions on the Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
- name: AMOUNT
|
||||
description: the borrowed amount in the currency listed in the CURRENCY column
|
||||
- name: AMOUNT_USD
|
||||
description: the borrowed amount in USD currency
|
||||
- name: CURRENCY
|
||||
description: the borrowed amount currency
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
- name: SOURCE
|
||||
description: The transaction source, either the Terra blockchain or sent via Wormhole
|
||||
138
models/gold/classic/classic__ez_anchor_burns.sql
Normal file
138
models/gold/classic/classic__ez_anchor_burns.sql
Normal file
@ -0,0 +1,138 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
|
||||
col_4_burns AS (
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :execute_msg :send :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
amount * price AS amount_usd,
|
||||
msg_value :contract :: STRING AS currency,
|
||||
msg_value :execute_msg :send :contract :: STRING AS contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND msg_value :contract :: STRING = o.currency
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :execute_msg :send :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
msg_value :execute_msg :send :msg :unbond IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
AND chain_id = 'columbus-4'
|
||||
),
|
||||
|
||||
msgs AS (
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :contract :: STRING AS currency,
|
||||
msg_value :execute_msg :send :contract :: STRING AS contract_address
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
WHERE
|
||||
msg_value :execute_msg :send :contract :: STRING = 'terra1mtwph2juhj0rvjz7dy92gvl6xvukaxu8rfv8ts' -- Anchor bLUNA Hub
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
AND chain_id = 'columbus-5'
|
||||
),
|
||||
|
||||
col_5_burns AS (
|
||||
SELECT
|
||||
m.blockchain,
|
||||
m.chain_id,
|
||||
m.block_id,
|
||||
m.block_timestamp,
|
||||
m.tx_id,
|
||||
sender,
|
||||
event_attributes :burnt_amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
amount * price AS amount_usd,
|
||||
m.currency,
|
||||
contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label
|
||||
FROM msgs m
|
||||
LEFT JOIN {{ ref('silver_classic__msg_events') }} e
|
||||
ON m.tx_id = e.tx_id
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
m.block_timestamp
|
||||
) = o.hour
|
||||
AND m.currency = o.currency
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE event_type = 'from_contract'
|
||||
AND event_attributes :burnt_amount IS NOT NULL
|
||||
)
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
sender,
|
||||
amount,
|
||||
amount_usd,
|
||||
currency,
|
||||
contract_address,
|
||||
contract_label
|
||||
FROM col_4_burns
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
sender,
|
||||
amount,
|
||||
amount_usd,
|
||||
currency,
|
||||
contract_address,
|
||||
contract_label
|
||||
FROM col_5_burns
|
||||
28
models/gold/classic/classic__ez_anchor_burns.yml
Normal file
28
models/gold/classic/classic__ez_anchor_burns.yml
Normal file
@ -0,0 +1,28 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_burns
|
||||
descriptions: |-
|
||||
This table records unbonding (burn) events on the Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
- name: AMOUNT
|
||||
description: the burned amount in the currency listed in the CURRENCY column
|
||||
- name: AMOUNT_USD
|
||||
description: the burned amount in USD currency
|
||||
- name: CURRENCY
|
||||
description: the burned amount currency
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
258
models/gold/classic/classic__ez_anchor_collateral.sql
Normal file
258
models/gold/classic/classic__ez_anchor_collateral.sql
Normal file
@ -0,0 +1,258 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
msgs AS (
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
'withdraw' AS action,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
COALESCE(msg_value :execute_msg :send :contract :: STRING, msg_value :contract :: STRING) AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON COALESCE(msg_value :execute_msg :send :contract :: STRING, msg_value :contract :: STRING) = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
msg_value :execute_msg :withdraw_collateral IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
events AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
CASE WHEN event_attributes :collaterals [0] :denom :: STRING = 'terra1z3e2e4jpk4n0xzzwlkgcfvc95pc5ldq0xcny58' -- whsAVAX
|
||||
THEN event_attributes :collaterals [0] :amount / pow(
|
||||
10,
|
||||
8
|
||||
) ELSE event_attributes :collaterals [0] :amount / pow(
|
||||
10,
|
||||
6
|
||||
) END AS amount,
|
||||
amount * price AS amount_usd,
|
||||
event_attributes :collaterals [0] :denom :: STRING AS currency
|
||||
FROM
|
||||
{{ ref('silver_classic__msg_events') }}
|
||||
m
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND event_attributes :collaterals [0] :denom :: STRING = o.currency
|
||||
WHERE
|
||||
tx_id IN(
|
||||
SELECT
|
||||
tx_id
|
||||
FROM
|
||||
msgs
|
||||
)
|
||||
AND event_type = 'from_contract'
|
||||
AND event_attributes :collaterals IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
|
||||
wormhole_msgs AS (
|
||||
SELECT DISTINCT
|
||||
tx_id
|
||||
FROM {{ ref('silver_classic__msgs') }}
|
||||
WHERE msg_value :execute_msg :process_anchor_message IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
|
||||
wormhole_deposits AS (
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.block_id,
|
||||
a.block_timestamp,
|
||||
a.chain_id,
|
||||
a.tx_id,
|
||||
a.msg_index,
|
||||
'provide' AS event_type,
|
||||
action_log :borrower::STRING AS sender,
|
||||
CASE WHEN event_attributes :collaterals [0] :denom::STRING = 'terra1z3e2e4jpk4n0xzzwlkgcfvc95pc5ldq0xcny58' --whsAVAX
|
||||
THEN action_log :amount / POW(
|
||||
10,
|
||||
8
|
||||
) ELSE action_log :amount / POW(
|
||||
10,
|
||||
6
|
||||
) END AS amount,
|
||||
action_contract_address AS contract_address,
|
||||
event_attributes :collaterals [0] :denom::STRING as currency
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
LEFT JOIN {{ ref('silver_classic__msg_events') }} e
|
||||
ON a.tx_id = e.tx_id AND a.msg_index = e.msg_index
|
||||
WHERE a.tx_id IN (SELECT tx_id FROM wormhole_msgs)
|
||||
AND action_method = 'lock_collateral'
|
||||
AND e.event_type = 'from_contract'
|
||||
AND action_log :amount IS NOT NULL
|
||||
),
|
||||
|
||||
wormhole_withdraws AS (
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.block_id,
|
||||
a.block_timestamp,
|
||||
a.chain_id,
|
||||
a.tx_id,
|
||||
a.msg_index,
|
||||
'withdraw' AS event_type,
|
||||
action_log :borrower::STRING AS sender,
|
||||
CASE WHEN event_attributes :collaterals [0] :denom::STRING = 'terra1z3e2e4jpk4n0xzzwlkgcfvc95pc5ldq0xcny58' --whsAVAX
|
||||
THEN action_log :amount / POW(
|
||||
10,
|
||||
8
|
||||
) ELSE action_log :amount / POW(
|
||||
10,
|
||||
6
|
||||
) END AS amount,
|
||||
action_contract_address AS contract_address,
|
||||
event_attributes :collaterals [0] :denom::STRING AS currency
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
LEFT JOIN {{ ref('silver_classic__msg_events') }} e
|
||||
ON a.tx_id = e.tx_id AND a.msg_index = e.msg_index
|
||||
WHERE a.tx_id IN (SELECT tx_id FROM wormhole_msgs)
|
||||
AND action_method = 'withdraw_collateral'
|
||||
AND e.event_type = 'from_contract'
|
||||
)
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
action AS event_type,
|
||||
sender,
|
||||
amount,
|
||||
amount_usd,
|
||||
currency,
|
||||
contract_address AS contract_address,
|
||||
COALESCE(contract_label, '') AS contract_label,
|
||||
'Terra' AS source
|
||||
FROM
|
||||
msgs m
|
||||
JOIN events e
|
||||
ON m.tx_id = e.tx_id
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
'provide' AS event_type,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
CASE WHEN msg_value :contract :: STRING = 'terra1z3e2e4jpk4n0xzzwlkgcfvc95pc5ldq0xcny58' --whsAVAX
|
||||
THEN msg_value :execute_msg :send :amount / pow(
|
||||
10,
|
||||
8
|
||||
)
|
||||
ELSE msg_value :execute_msg :send :amount / pow(
|
||||
10,
|
||||
6
|
||||
) END AS amount,
|
||||
amount * price AS amount_usd,
|
||||
msg_value :contract :: STRING AS currency,
|
||||
COALESCE(msg_value :execute_msg :send :contract :: STRING, msg_value :contract :: STRING) AS contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label,
|
||||
'Terra' AS source
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON COALESCE(msg_value :execute_msg :send :contract :: STRING, msg_value :contract :: STRING) = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND msg_value :contract :: STRING = o.currency
|
||||
WHERE
|
||||
tx_id in (select tx_id from {{ ref('silver_classic__msgs') }} where msg_value:execute_msg:lock_collateral is not null)
|
||||
and tx_status = 'SUCCEEDED'
|
||||
and msg_value :execute_msg :send :contract::STRING IN ('terra1ptjp2vfjrwh0j0faj9r6katm640kgjxnwwq9kn', 'terra10cxuzggyvvv44magvrh3thpdnk9cmlgk93gmx2',
|
||||
'terra1zdxlrtyu74gf6pvjkg9t22hentflmfcs86llva') --Anchor Custody and bATOM Contracts
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
d.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
event_type,
|
||||
sender,
|
||||
amount,
|
||||
amount * price AS amount_usd,
|
||||
d.currency,
|
||||
contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label,
|
||||
'Wormhole' AS source
|
||||
FROM
|
||||
wormhole_deposits d
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON d.contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND d.currency = o.currency
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
w.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
event_type,
|
||||
sender,
|
||||
amount,
|
||||
amount * price AS amount_usd,
|
||||
w.currency,
|
||||
contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label,
|
||||
'Wormhole' AS source
|
||||
FROM
|
||||
wormhole_withdraws w
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON w.contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND w.currency = o.currency
|
||||
32
models/gold/classic/classic__ez_anchor_collateral.yml
Normal file
32
models/gold/classic/classic__ez_anchor_collateral.yml
Normal file
@ -0,0 +1,32 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_collateral
|
||||
descriptions: |-
|
||||
This table records locking and withdrawing collateral events on the Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
- name: EVENT_TYPE
|
||||
description: the event type for this transaction
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
- name: AMOUNT
|
||||
description: the burned amount in the currency listed in the CURRENCY column
|
||||
- name: AMOUNT_USD
|
||||
description: the burned amount in USD currency
|
||||
- name: CURRENCY
|
||||
description: the burned amount currency
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
- name: SOURCE
|
||||
description: The transaction source, either the Terra blockchain or sent via Wormhole
|
||||
184
models/gold/classic/classic__ez_anchor_deposits.sql
Normal file
184
models/gold/classic/classic__ez_anchor_deposits.sql
Normal file
@ -0,0 +1,184 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
msgs AS (
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_index,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :coins [0] :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS deposit_amount,
|
||||
deposit_amount * price AS deposit_amount_usd,
|
||||
msg_value :coins [0] :denom :: STRING AS deposit_currency,
|
||||
msg_value :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND msg_value :coins [0] :denom :: STRING = o.currency
|
||||
WHERE
|
||||
msg_value :execute_msg :deposit_stable IS NOT NULL
|
||||
AND msg_value :contract :: STRING = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
events AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_index,
|
||||
event_attributes :mint_amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS mint_amount,
|
||||
mint_amount * price AS mint_amount_usd,
|
||||
event_attributes :"1_contract_address" :: STRING AS mint_currency
|
||||
FROM
|
||||
{{ ref('silver_classic__msg_events') }}
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = o.hour
|
||||
AND event_attributes :"1_contract_address" :: STRING = o.currency
|
||||
WHERE
|
||||
event_type = 'from_contract'
|
||||
AND tx_id IN(
|
||||
SELECT
|
||||
tx_id
|
||||
FROM
|
||||
msgs
|
||||
)
|
||||
AND event_attributes :"0_action" :: STRING = 'deposit_stable'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
|
||||
deposits AS (
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.chain_id,
|
||||
a.block_id,
|
||||
a.block_timestamp,
|
||||
a.tx_id,
|
||||
a.msg_index,
|
||||
action_index,
|
||||
action_log :depositor :: STRING AS sender,
|
||||
action_log :deposit_amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS deposit_amount,
|
||||
action_log :mint_amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS mint_amount,
|
||||
coalesce(msg_value :coins [0] :denom :: STRING, 'uusd') AS deposit_currency,
|
||||
action_contract_address AS contract_address,
|
||||
CASE WHEN
|
||||
msg_value :execute_msg :process_anchor_message IS NOT NULL
|
||||
THEN 'Wormhole'
|
||||
ELSE 'Terra'
|
||||
END AS source
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
LEFT JOIN {{ ref('silver_classic__msgs') }} m
|
||||
ON a.tx_id = m.tx_id AND a.msg_index = m.msg_index
|
||||
WHERE action_method = 'deposit_stable'
|
||||
)
|
||||
|
||||
SELECT DISTINCT *
|
||||
FROM (
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
sender,
|
||||
deposit_amount,
|
||||
deposit_amount_usd,
|
||||
deposit_currency,
|
||||
mint_amount,
|
||||
mint_amount_usd,
|
||||
mint_currency,
|
||||
contract_address,
|
||||
contract_label,
|
||||
'Terra' AS source
|
||||
FROM
|
||||
msgs m
|
||||
JOIN events e
|
||||
ON m.tx_id = e.tx_id
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
d.blockchain,
|
||||
d.chain_id,
|
||||
d.block_id,
|
||||
d.block_timestamp,
|
||||
d.tx_id,
|
||||
sender,
|
||||
deposit_amount,
|
||||
deposit_amount * o.price AS deposit_amount_usd,
|
||||
deposit_currency,
|
||||
mint_amount,
|
||||
mint_amount * p.price AS mint_amount_usd,
|
||||
action_contract_address AS mint_currency,
|
||||
contract_address,
|
||||
l.address_name AS contract_label,
|
||||
source
|
||||
FROM
|
||||
deposits d
|
||||
LEFT JOIN {{ ref('silver_classic__event_actions') }} m
|
||||
ON d.tx_id = m.tx_id
|
||||
AND d.msg_index = m.msg_index
|
||||
AND sender = action_log :to::STRING
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
d.block_timestamp
|
||||
) = o.hour
|
||||
AND deposit_currency = o.currency
|
||||
LEFT OUTER JOIN prices p
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
d.block_timestamp
|
||||
) = p.hour
|
||||
AND action_contract_address = p.currency
|
||||
WHERE action_method = 'mint'
|
||||
AND action_contract_address = 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu' --aUST
|
||||
)
|
||||
50
models/gold/classic/classic__ez_anchor_deposits.yml
Normal file
50
models/gold/classic/classic__ez_anchor_deposits.yml
Normal file
@ -0,0 +1,50 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_deposits
|
||||
descriptions: |-
|
||||
This table records deposit actions on the Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
|
||||
- name: DEPOSIT_AMOUNT
|
||||
description: the deposited amount in the currency listed in the CURRENCY column
|
||||
|
||||
- name: DEPOSIT_AMOUNT_USD
|
||||
description: the deposited amount in USD currency
|
||||
|
||||
- name: DEPOSIT_CURRENCY
|
||||
description: the deposited amount currency
|
||||
|
||||
- name: MINT_AMOUNT
|
||||
description: the minted amount in the currency listed in the CURRENCY column
|
||||
|
||||
- name: MINT_AMOUNT_USD
|
||||
description: the minted amount in USD currency
|
||||
|
||||
- name: MINT_CURRENCY
|
||||
description: the minted amount currency
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
tests:
|
||||
- name: SOURCE
|
||||
description: The transaction source, either the Terra blockchain or sent via Wormhole
|
||||
|
||||
139
models/gold/classic/classic__ez_anchor_gov_staking.sql
Normal file
139
models/gold/classic/classic__ez_anchor_gov_staking.sql
Normal file
@ -0,0 +1,139 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR',
|
||||
'PURPOSE': 'STAKING' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
stake_msgs AS (
|
||||
SELECT
|
||||
t.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :execute_msg :send :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
amount * o.price AS amount_usd,
|
||||
msg_value :contract :: STRING AS currency,
|
||||
msg_value :execute_msg :send :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
t
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
t.block_timestamp
|
||||
) = o.hour
|
||||
AND msg_value :contract :: STRING = o.currency
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :execute_msg :send :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
(
|
||||
msg_value :execute_msg :send :msg :stake_voting_tokens IS NOT NULL
|
||||
AND msg_value :execute_msg :send :contract :: STRING = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
)
|
||||
OR
|
||||
(
|
||||
msg_value:execute_msg:send:msg::string = 'eyJzdGFrZV92b3RpbmdfdG9rZW5zIjp7fX0='
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
)
|
||||
),
|
||||
stake_events AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_index,
|
||||
event_attributes :share AS shares
|
||||
FROM
|
||||
{{ ref('silver_classic__msg_events') }}
|
||||
WHERE
|
||||
tx_id IN(
|
||||
SELECT
|
||||
DISTINCT tx_id
|
||||
FROM
|
||||
stake_msgs
|
||||
)
|
||||
AND event_type = 'from_contract'
|
||||
AND event_attributes :share IS NOT NULL
|
||||
) -- Staking
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
msg_index,
|
||||
'stake' AS event_type,
|
||||
sender,
|
||||
amount,
|
||||
amount_usd,
|
||||
currency,
|
||||
shares,
|
||||
contract_address,
|
||||
contract_label
|
||||
FROM
|
||||
stake_msgs m
|
||||
JOIN stake_events e
|
||||
ON m.tx_id = e.tx_id
|
||||
UNION
|
||||
-- Unstaking
|
||||
SELECT
|
||||
t.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
null AS msg_index,
|
||||
'unstake' AS event_type,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :execute_msg :withdraw_voting_tokens :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
amount * o.price AS amount_usd,
|
||||
'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' AS currency,
|
||||
NULL AS shares,
|
||||
msg_value :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
t
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
t.block_timestamp
|
||||
) = o.hour
|
||||
AND 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' = o.currency
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
msg_value :execute_msg :withdraw_voting_tokens IS NOT NULL
|
||||
AND msg_value :contract :: STRING = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
|
||||
|
||||
40
models/gold/classic/classic__ez_anchor_gov_staking.yml
Normal file
40
models/gold/classic/classic__ez_anchor_gov_staking.yml
Normal file
@ -0,0 +1,40 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_gov_staking
|
||||
descriptions: |-
|
||||
This table records the staking and withdrawing of voting tokens on Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: EVENT_TYPE
|
||||
description: the event type for this transaction
|
||||
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
|
||||
- name: AMOUNT
|
||||
description: the burned amount in the currency listed in the CURRENCY column
|
||||
|
||||
- name: AMOUNT_USD
|
||||
description: the burned amount in USD currency
|
||||
|
||||
- name: CURRENCY
|
||||
description: the burned amount currency
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
@ -0,0 +1,71 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH msgs AS (
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :sender :: STRING AS creator,
|
||||
msg_value :execute_msg :send :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
msg_value :execute_msg :send :msg :create_poll :title :: STRING AS title,
|
||||
msg_value :execute_msg :send :msg :create_poll :link :: STRING AS link,
|
||||
msg_value :execute_msg :send :msg :create_poll :description :: STRING AS description,
|
||||
msg_value :execute_msg :send :msg :create_poll :execute_msg :msg AS msg,
|
||||
msg_value :execute_msg :send :contract :: STRING AS contract_address
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
WHERE
|
||||
msg_value :execute_msg :send :msg :create_poll IS NOT NULL
|
||||
AND msg_value :execute_msg :send :contract :: STRING = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
events AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
COALESCE(TO_TIMESTAMP(event_attributes :end_time), event_attributes :end_height) AS end_time,
|
||||
event_attributes :poll_id AS poll_id
|
||||
FROM
|
||||
{{ ref('silver_classic__msg_events') }}
|
||||
WHERE
|
||||
tx_id IN(
|
||||
SELECT
|
||||
tx_id
|
||||
FROM
|
||||
msgs
|
||||
)
|
||||
AND event_type = 'from_contract'
|
||||
)
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
poll_id,
|
||||
end_time,
|
||||
m.creator,
|
||||
amount,
|
||||
title,
|
||||
link,
|
||||
description,
|
||||
msg,
|
||||
contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
msgs m
|
||||
JOIN events e
|
||||
ON m.tx_id = e.tx_id
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_gov_submit_proposal
|
||||
descriptions: |-
|
||||
This table records governance proposal submissions on Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: POLL_ID
|
||||
description: the identifier of this poll
|
||||
|
||||
- name: END_TIME
|
||||
description: the end time for the government proposal
|
||||
|
||||
- name: CREATOR
|
||||
description: the address which created this government vote proposal
|
||||
|
||||
- name: AMOUNT
|
||||
description: the amount they put into this proposal
|
||||
|
||||
- name: TITLE
|
||||
description: proposal title
|
||||
|
||||
- name: LINK
|
||||
description: proposal link
|
||||
|
||||
- name: DESCRIPTION
|
||||
description: proposal description
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
|
||||
31
models/gold/classic/classic__ez_anchor_gov_vote.sql
Normal file
31
models/gold/classic/classic__ez_anchor_gov_vote.sql
Normal file
@ -0,0 +1,31 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
m.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_value :sender :: STRING AS voter,
|
||||
msg_value :execute_msg :cast_vote :poll_id AS poll_id,
|
||||
msg_value :execute_msg :cast_vote :vote :: STRING AS vote,
|
||||
msg_value :execute_msg :cast_vote :amount / pow(
|
||||
10,
|
||||
6
|
||||
) AS balance,
|
||||
msg_value :contract :: STRING AS contract_address,
|
||||
l.address_name AS contract_label
|
||||
FROM
|
||||
{{ ref('silver_classic__msgs') }}
|
||||
m
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
WHERE
|
||||
msg_value :contract :: STRING = 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5' -- ANC Governance
|
||||
AND msg_value :execute_msg :cast_vote IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
39
models/gold/classic/classic__ez_anchor_gov_vote.yml
Normal file
39
models/gold/classic/classic__ez_anchor_gov_vote.yml
Normal file
@ -0,0 +1,39 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_gov_vote
|
||||
descriptions: |-
|
||||
This table records Anchor governance proposal votes.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: VOTER
|
||||
description: the voter address for this proposal
|
||||
|
||||
- name: POLL_ID
|
||||
description: the identifier of this poll
|
||||
|
||||
- name: VOTE
|
||||
description: the vote decition to this proposal, yes or no
|
||||
|
||||
- name: BALANCE
|
||||
description: the balance of voting tokens
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
|
||||
100
models/gold/classic/classic__ez_anchor_liquidations.sql
Normal file
100
models/gold/classic/classic__ez_anchor_liquidations.sql
Normal file
@ -0,0 +1,100 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC('hour', block_timestamp) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM {{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
|
||||
),
|
||||
|
||||
liquidations AS (
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
action_index,
|
||||
msg_index,
|
||||
action_log :borrower::STRING AS borrower,
|
||||
action_log :liquidator::STRING AS liquidator,
|
||||
action_log :amount / POW(10,6) AS liquidated_amount,
|
||||
action_contract_address AS contract_address
|
||||
FROM {{ ref('silver_classic__event_actions') }}
|
||||
WHERE action_method = 'liquidate_collateral'
|
||||
),
|
||||
|
||||
bid_fees AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_index,
|
||||
action_log :bid_fee / POW(10,6) AS bid_fee,
|
||||
action_log :collateral_amount / POW(10,6) AS amount,
|
||||
action_log :collateral_token::STRING AS liquidated_currency
|
||||
FROM {{ ref('silver_classic__event_actions') }}
|
||||
WHERE action_method = 'execute_bid'
|
||||
),
|
||||
|
||||
premium_rate AS (
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_value:execute_msg:submit_bid:collateral_token ::STRING AS collateral_token,
|
||||
msg_value:execute_msg:submit_bid:premium_rate AS premium_rate
|
||||
FROM {{ ref('silver_classic__msgs') }}
|
||||
WHERE msg_value:execute_msg:submit_bid:premium_rate IS NOT NULL
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
)
|
||||
|
||||
SELECT DISTINCT * FROM (
|
||||
SELECT
|
||||
l.blockchain,
|
||||
l.chain_id,
|
||||
l.block_id,
|
||||
l.block_timestamp,
|
||||
l.tx_id,
|
||||
bid_fee,
|
||||
premium_rate,
|
||||
borrower,
|
||||
liquidator,
|
||||
liquidated_amount,
|
||||
liquidated_amount * price AS liquidated_amount_usd,
|
||||
liquidated_currency,
|
||||
contract_address,
|
||||
COALESCE(la.address_name, '') AS contract_label
|
||||
FROM liquidations l
|
||||
|
||||
LEFT JOIN bid_fees b
|
||||
ON l.tx_id = b.tx_id
|
||||
AND l.liquidated_amount = b.amount
|
||||
AND l.msg_index = b.msg_index
|
||||
|
||||
LEFT JOIN premium_rate p
|
||||
ON b.tx_id = p.tx_id
|
||||
AND b.liquidated_currency = p.collateral_token
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS la
|
||||
ON l.contract_address = la.address AND la.blockchain = 'terra' AND la.creator = 'flipside'
|
||||
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
l.block_timestamp
|
||||
) = o.hour
|
||||
AND b.liquidated_currency = o.currency
|
||||
)
|
||||
45
models/gold/classic/classic__ez_anchor_liquidations.yml
Normal file
45
models/gold/classic/classic__ez_anchor_liquidations.yml
Normal file
@ -0,0 +1,45 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_liquidations
|
||||
descriptions: |-
|
||||
This table records liquidations on Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: BID_FEE
|
||||
description: fee for placing a bid.
|
||||
|
||||
- name: BORROWER
|
||||
description: the borrower address
|
||||
|
||||
- name: LIQUIDATOR
|
||||
description: the liquidator address
|
||||
|
||||
- name: LIQUIDATED_AMOUNT
|
||||
description: the liquidated amount in the currency listed in the CURRENCY column
|
||||
|
||||
- name: LIQUIDATED_AMOUNT_USD
|
||||
description: the liquidated amount in USD
|
||||
|
||||
- name: LIQUIDATED_CURRENCY
|
||||
description: the liquidated currency
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
|
||||
175
models/gold/classic/classic__ez_anchor_redeem.sql
Normal file
175
models/gold/classic/classic__ez_anchor_redeem.sql
Normal file
@ -0,0 +1,175 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
|
||||
redeem_events AS (
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
tx_status,
|
||||
msg_index,
|
||||
event_attributes
|
||||
FROM {{ ref('silver_classic__msg_events') }}
|
||||
WHERE tx_id in (select tx_id from {{ ref('silver_classic__msgs') }} WHERE msg_value:contract::string = 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu')
|
||||
AND event_type = 'from_contract'
|
||||
AND event_attributes:redeem_amount is not null
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
|
||||
wormhole_txs AS (
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
action_log:redeem_amount::FLOAT / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
action_contract_address AS contract_address,
|
||||
'Wormhole' AS source
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
WHERE action_method = 'redeem_stable'
|
||||
AND tx_id IN (SELECT tx_id FROM {{ ref('silver_classic__msgs') }} WHERE msg_value :execute_msg :process_anchor_message IS NOT NULL)
|
||||
|
||||
),
|
||||
|
||||
other_txs AS (
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.chain_id,
|
||||
a.block_id,
|
||||
a.block_timestamp,
|
||||
a.tx_id,
|
||||
m.msg_index,
|
||||
msg_value :sender::STRING AS sender,
|
||||
action_log:redeem_amount::FLOAT / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
action_contract_address AS contract_address
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
LEFT JOIN {{ ref('silver_classic__msgs') }} m
|
||||
ON a.tx_id = m.tx_id AND a.msg_index = m.msg_index
|
||||
WHERE action_method = 'redeem_stable'
|
||||
AND msg_value :execute_msg :process_anchor_message IS NULL
|
||||
AND a.tx_id NOT IN (SELECT DISTINCT tx_id FROM redeem_events)
|
||||
AND m.msg_index IS NOT NULL
|
||||
)
|
||||
|
||||
SELECT DISTINCT * FROM (
|
||||
SELECT
|
||||
e.blockchain,
|
||||
e.chain_id,
|
||||
e.block_id,
|
||||
e.block_timestamp,
|
||||
e.tx_id,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
event_attributes:redeem_amount::FLOAT / pow(
|
||||
10,
|
||||
6
|
||||
) AS amount,
|
||||
amount * price AS amount_usd,
|
||||
msg_value :contract :: STRING AS currency,
|
||||
COALESCE(msg_value :execute_msg :send :contract :: STRING, '') AS contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label,
|
||||
'Terra' AS source
|
||||
FROM redeem_events e
|
||||
JOIN {{ ref('silver_classic__msgs') }} m
|
||||
ON e.tx_id = m.tx_id
|
||||
AND e.msg_index = m.msg_index
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON msg_value :execute_msg :send :contract :: STRING = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices r
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
e.block_timestamp
|
||||
) = HOUR
|
||||
AND msg_value :contract :: STRING = r.currency
|
||||
WHERE e.tx_status = 'SUCCEEDED'
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
w.blockchain,
|
||||
w.chain_id,
|
||||
w.block_id,
|
||||
w.block_timestamp,
|
||||
w.tx_id,
|
||||
action_log :from::STRING AS sender,
|
||||
amount,
|
||||
amount * price AS amount_usd,
|
||||
action_contract_address AS currency,
|
||||
contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label,
|
||||
source
|
||||
FROM wormhole_txs w
|
||||
LEFT JOIN {{ ref('silver_classic__event_actions') }} e
|
||||
ON w.tx_id = e.tx_id
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON w.contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices r
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
w.block_timestamp
|
||||
) = HOUR
|
||||
AND action_contract_address = r.currency
|
||||
WHERE action_method = 'send'
|
||||
AND action_log :to::STRING = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' --Anchor market
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
o.blockchain,
|
||||
o.chain_id,
|
||||
o.block_id,
|
||||
o.block_timestamp,
|
||||
o.tx_id,
|
||||
COALESCE(o.sender, action_log :from::STRING) AS sender,
|
||||
amount,
|
||||
amount * price AS amount_usd,
|
||||
action_contract_address AS currency,
|
||||
contract_address,
|
||||
COALESCE(l.address_name, '') AS contract_label,
|
||||
'Terra' AS source
|
||||
FROM other_txs o
|
||||
LEFT JOIN {{ ref('silver_classic__event_actions') }} e
|
||||
ON o.tx_id = e.tx_id
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
LEFT OUTER JOIN prices r
|
||||
ON DATE_TRUNC(
|
||||
'hour',
|
||||
o.block_timestamp
|
||||
) = HOUR
|
||||
AND action_contract_address = r.currency
|
||||
WHERE action_method = 'send'
|
||||
AND action_log :to::STRING = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' --Anchor market
|
||||
)
|
||||
42
models/gold/classic/classic__ez_anchor_redeem.yml
Normal file
42
models/gold/classic/classic__ez_anchor_redeem.yml
Normal file
@ -0,0 +1,42 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_redeem
|
||||
descriptions: |-
|
||||
This table records redemption events on Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
|
||||
- name: AMOUNT
|
||||
description: the redeem amount in the currency listed in the CURRENCY column
|
||||
|
||||
- name: AMOUNT_USD
|
||||
description: the redeem amount in USD currency
|
||||
|
||||
- name: CURRENCY
|
||||
description: the redeem amount currency
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
|
||||
- name: SOURCE
|
||||
description: The transaction source, either the Terra blockchain or sent via Wormhole
|
||||
|
||||
60
models/gold/classic/classic__ez_anchor_repay.sql
Normal file
60
models/gold/classic/classic__ez_anchor_repay.sql
Normal file
@ -0,0 +1,60 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC('hour', block_timestamp) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM {{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE
|
||||
1 = 1
|
||||
GROUP BY 1,
|
||||
2,
|
||||
3
|
||||
|
||||
)
|
||||
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.chain_id,
|
||||
a.block_id,
|
||||
a.block_timestamp,
|
||||
a.tx_id,
|
||||
msg_value :sender::STRING AS sender,
|
||||
COALESCE(action_log :borrower::STRING, action_contract_address) AS borrower,
|
||||
COALESCE(action_log :repay_amount / POW(10,6),
|
||||
action_log :withdraw_amount_ust / POW(10,6)) AS amount,
|
||||
amount * p.price AS amount_usd,
|
||||
COALESCE(msg_value :coins [0] :denom :: STRING, 'uusd') AS currency,
|
||||
action_contract_address AS contract_address,
|
||||
l.address_name AS contract_label,
|
||||
CASE WHEN
|
||||
msg_value :execute_msg :process_anchor_message IS NOT NULL
|
||||
THEN 'Wormhole'
|
||||
ELSE 'Terra'
|
||||
END AS source
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
|
||||
LEFT JOIN {{ ref('silver_classic__msgs') }} m
|
||||
ON a.tx_id = m.tx_id AND a.msg_index = m.msg_index
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON action_contract_address = l.address
|
||||
AND l.blockchain = 'terra'
|
||||
AND l.creator = 'flipside'
|
||||
|
||||
LEFT OUTER JOIN prices p
|
||||
ON DATE_TRUNC('hour', a.block_timestamp) = HOUR
|
||||
AND COALESCE(msg_value :coins [0] :denom :: STRING, 'uusd') = p.currency
|
||||
|
||||
WHERE action_method = 'repay_stable'
|
||||
AND COALESCE(action_log :repay_amount, action_log :withdraw_amount_ust) IS NOT NULL
|
||||
AND m.msg_index IS NOT NULL
|
||||
|
||||
45
models/gold/classic/classic__ez_anchor_repay.yml
Normal file
45
models/gold/classic/classic__ez_anchor_repay.yml
Normal file
@ -0,0 +1,45 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_repay
|
||||
descriptions: |-
|
||||
This table records repayment events on Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
|
||||
- name: BORROWER
|
||||
description: the sender address for this transaction
|
||||
|
||||
- name: AMOUNT
|
||||
description: the repay amount in the currency listed in the CURRENCY column
|
||||
|
||||
- name: AMOUNT_USD
|
||||
description: the repay amount in USD currency
|
||||
|
||||
- name: CURRENCY
|
||||
description: the repay amount currency
|
||||
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: Anchor contract address
|
||||
|
||||
- name: CONTRACT_LABEL
|
||||
description: Anchor contract address in the label
|
||||
|
||||
- name: SOURCE
|
||||
description: The transaction source, either the Terra blockchain or sent via Wormhole
|
||||
|
||||
268
models/gold/classic/classic__ez_anchor_reward_claims.sql
Normal file
268
models/gold/classic/classic__ez_anchor_reward_claims.sql
Normal file
@ -0,0 +1,268 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ANCHOR' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC('hour', block_timestamp) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM {{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE 1 = 1
|
||||
GROUP BY 1,
|
||||
2,
|
||||
3
|
||||
|
||||
),
|
||||
|
||||
reward_claims as (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM {{ ref('silver_classic__msgs') }}
|
||||
WHERE msg_value:execute_msg:claim_rewards IS NOT NULL
|
||||
AND msg_value:contract::string = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
|
||||
withdraw_claims as (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM {{ ref('silver_classic__msgs') }}
|
||||
WHERE msg_value :execute_msg :withdraw IS NOT NULL
|
||||
AND msg_value :contract :: STRING = 'terra1897an2xux840p9lrh6py3ryankc6mspw49xse3'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
),
|
||||
|
||||
reward_claims_events as (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM {{ ref('silver_classic__msg_events') }}
|
||||
WHERE event_type = 'from_contract'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
AND event_attributes :"0_action" :: STRING = 'claim_rewards'
|
||||
),
|
||||
|
||||
multi_withdraw_msgs AS (
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_index,
|
||||
msg_value :contract :: STRING AS claim_0_contract
|
||||
FROM withdraw_claims
|
||||
WHERE msg_index = 0
|
||||
|
||||
),
|
||||
|
||||
multi_claim_msgs AS (
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_index,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :contract :: STRING AS claim_1_contract
|
||||
FROM reward_claims
|
||||
WHERE msg_index = 1
|
||||
|
||||
),
|
||||
|
||||
multi_withdraw AS (
|
||||
|
||||
SELECT
|
||||
m.tx_id,
|
||||
claim_0_contract,
|
||||
event_attributes :"0_amount" / pow(10,6) AS claim_0_amount,
|
||||
event_attributes :"1_contract_address" :: STRING AS claim_0_currency
|
||||
FROM {{ ref('silver_classic__msg_events') }} e
|
||||
|
||||
JOIN multi_withdraw_msgs m
|
||||
ON m.tx_id = e.tx_id
|
||||
AND m.msg_index = e.msg_index
|
||||
|
||||
WHERE event_type = 'from_contract'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
AND event_attributes :"0_action" :: STRING = 'withdraw'
|
||||
),
|
||||
|
||||
multi_claim AS (
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
sender,
|
||||
claim_1_contract,
|
||||
event_attributes :claim_amount / pow(10,6) AS claim_1_amount,
|
||||
event_attributes :"2_contract_address" :: STRING AS claim_1_currency
|
||||
FROM reward_claims_events e
|
||||
|
||||
JOIN multi_claim_msgs m
|
||||
ON m.tx_id = e.tx_id
|
||||
AND m.msg_index = e.msg_index
|
||||
|
||||
),
|
||||
|
||||
single_claim_msgs AS (
|
||||
|
||||
SELECT
|
||||
tx_id,
|
||||
msg_index,
|
||||
msg_value :sender :: STRING AS sender,
|
||||
msg_value :contract :: STRING AS claim_1_contract
|
||||
FROM reward_claims
|
||||
WHERE tx_id NOT IN(SELECT
|
||||
DISTINCT tx_id
|
||||
FROM multi_claim_msgs)
|
||||
|
||||
),
|
||||
|
||||
single_claim_events AS (
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
m.tx_id,
|
||||
sender,
|
||||
claim_1_contract,
|
||||
event_attributes :claim_amount / pow(10,6) AS claim_1_amount,
|
||||
event_attributes :"2_contract_address" :: STRING AS claim_1_currency
|
||||
FROM reward_claims_events
|
||||
e
|
||||
|
||||
JOIN single_claim_msgs m
|
||||
ON m.tx_id = e.tx_id
|
||||
AND m.msg_index = e.msg_index
|
||||
|
||||
),
|
||||
|
||||
single_withdraw_msgs AS (
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
msg_index,
|
||||
msg_value :sender :: STRING as sender,
|
||||
msg_value :contract :: STRING AS contract_address
|
||||
FROM withdraw_claims
|
||||
WHERE tx_id NOT IN(SELECT
|
||||
DISTINCT tx_id
|
||||
FROM multi_claim_msgs)
|
||||
|
||||
),
|
||||
|
||||
all_claims AS (
|
||||
|
||||
SELECT
|
||||
C.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
C.tx_id,
|
||||
sender,
|
||||
claim_0_amount,
|
||||
claim_0_currency,
|
||||
claim_0_contract,
|
||||
claim_1_amount,
|
||||
claim_1_currency,
|
||||
claim_1_contract
|
||||
FROM
|
||||
multi_claim C
|
||||
|
||||
JOIN multi_withdraw w
|
||||
ON C.tx_id = w.tx_id
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
sender,
|
||||
0 as claim_0_amount,
|
||||
'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' as claim_0_currency,
|
||||
'terra1897an2xux840p9lrh6py3ryankc6mspw49xse3' as claim_0_contract,
|
||||
claim_1_amount,
|
||||
claim_1_currency,
|
||||
claim_1_contract
|
||||
FROM
|
||||
single_claim_events
|
||||
|
||||
UNION
|
||||
|
||||
SELECT
|
||||
m.blockchain,
|
||||
m.chain_id,
|
||||
m.block_id,
|
||||
m.block_timestamp,
|
||||
m.tx_id,
|
||||
m.sender,
|
||||
event_attributes :"0_amount" / pow(10,6) AS claim_0_amount,
|
||||
event_attributes :"1_contract_address" :: STRING AS claim_0_currency,
|
||||
m.contract_address AS claim_0_contract,
|
||||
0 as claim_1_amount,
|
||||
'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76' as claim_1_currency,
|
||||
'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s' as claim_1_contract
|
||||
FROM {{ ref('silver_classic__msg_events') }} e
|
||||
|
||||
JOIN single_withdraw_msgs m
|
||||
ON m.tx_id = e.tx_id
|
||||
AND m.msg_index = e.msg_index
|
||||
|
||||
WHERE event_type = 'from_contract'
|
||||
AND tx_status = 'SUCCEEDED'
|
||||
AND event_attributes :"0_action" :: STRING = 'withdraw'
|
||||
)
|
||||
|
||||
SELECT
|
||||
c.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
block_timestamp,
|
||||
c.tx_id,
|
||||
sender,
|
||||
claim_0_amount,
|
||||
claim_0_amount * p0.price AS claim_0_amount_usd,
|
||||
claim_0_currency,
|
||||
claim_0_contract,
|
||||
l0.address_name AS claim_0_contract_label,
|
||||
claim_1_amount,
|
||||
claim_1_amount * p1.price AS claim_1_amount_usd,
|
||||
claim_1_currency,
|
||||
claim_1_contract,
|
||||
l1.address_name AS claim_1_contract_label
|
||||
FROM
|
||||
all_claims c
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l0
|
||||
ON claim_0_contract = l0.address
|
||||
AND l0.blockchain = 'terra'
|
||||
AND l0.creator = 'flipside'
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l1
|
||||
ON claim_1_contract = l1.address
|
||||
AND l1.blockchain = 'terra'
|
||||
AND l1.creator = 'flipside'
|
||||
|
||||
LEFT OUTER JOIN prices p0
|
||||
ON DATE_TRUNC( 'hour', block_timestamp) = p0.hour
|
||||
AND claim_0_currency = p0.currency
|
||||
|
||||
LEFT OUTER JOIN prices p1
|
||||
ON DATE_TRUNC('hour',block_timestamp) = p1.hour
|
||||
AND claim_1_currency = p1.currency
|
||||
52
models/gold/classic/classic__ez_anchor_reward_claims.yml
Normal file
52
models/gold/classic/classic__ez_anchor_reward_claims.yml
Normal file
@ -0,0 +1,52 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_anchor_reward_claims
|
||||
descriptions: |-
|
||||
This table records claims of staking and market rewards for the Anchor protocol.
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
description: the blockchain this transaction sit on
|
||||
- name: CHAIN_ID
|
||||
description: the blockchain id for this transaction, in Terra, there are columbus-4 and columbus-5
|
||||
|
||||
- name: BLOCK_ID
|
||||
description: the block number for this transaction
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: the timestamp this transaction get generated
|
||||
|
||||
- name: TX_ID
|
||||
description: the unique identifier to find this transaction
|
||||
|
||||
- name: SENDER
|
||||
description: the sender address for this transaction
|
||||
|
||||
- name: CLAIM_0_AMOUNT
|
||||
description: Amount of token 0 claimed
|
||||
|
||||
- name: CLAIM_0_AMOUNT_USD
|
||||
description: Amount of token 0 claimed, in USD
|
||||
|
||||
- name: CLAIM_0_CURRENCY
|
||||
description: Currency of token 0 claimed
|
||||
|
||||
- name: CLAIM_0_CONTRACT
|
||||
description: Token 0 contract address
|
||||
|
||||
- name: CLAIM_0_CONTRACT_LABEL
|
||||
description: Token 0 contract label
|
||||
|
||||
- name: CLAIM_1_AMOUNT
|
||||
description: Amount of token 1 claimed
|
||||
|
||||
- name: CLAIM_1_AMOUNT_USD
|
||||
description: Amount of token 1 claimed, in USD
|
||||
|
||||
- name: CLAIM_1_CURRENCY
|
||||
description: Currency of token 1 claimed
|
||||
|
||||
- name: CLAIM_1_CONTRACT
|
||||
description: Token 1 contract address
|
||||
|
||||
- name: CLAIM_1_CONTRACT_LABEL
|
||||
description: Token 1 contract label
|
||||
116
models/gold/classic/classic__ez_astroport_swaps.sql
Normal file
116
models/gold/classic/classic__ez_astroport_swaps.sql
Normal file
@ -0,0 +1,116 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['classic'],
|
||||
meta ={ 'database_tags':{ 'table':{ 'PROTOCOL': 'ASTROPORT',
|
||||
'PURPOSE': 'DEX, SWAPS' }} }
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
DATE_TRUNC('hour',block_timestamp) AS HOUR,
|
||||
currency,
|
||||
symbol,
|
||||
AVG(price_usd) AS price
|
||||
FROM
|
||||
{{ ref('classic__dim_oracle_prices') }}
|
||||
WHERE 1=1
|
||||
GROUP BY
|
||||
1,
|
||||
2,
|
||||
3
|
||||
),
|
||||
|
||||
source_event_actions AS (
|
||||
SELECT
|
||||
a.blockchain,
|
||||
a.chain_id,
|
||||
a.block_id,
|
||||
a.msg_index,
|
||||
action_index AS tx_index,
|
||||
a.block_timestamp,
|
||||
a.tx_id,
|
||||
coalesce(msg_value :sender :: STRING, action_log :sender ::STRING) AS sender,
|
||||
CASE
|
||||
WHEN action_log :offer_asset::STRING = 'terra1mddcdx0ujx89f38gu7zspk2r2ffdl5enyz2u03' THEN action_log :offer_amount:: numeric / pow(10,8)
|
||||
ELSE action_log :offer_amount:: numeric / pow(10,6)
|
||||
END AS offer_amount,
|
||||
action_log :offer_asset::STRING AS offer_currency,
|
||||
CASE
|
||||
WHEN action_log :ask_asset::STRING = 'terra1mddcdx0ujx89f38gu7zspk2r2ffdl5enyz2u03' THEN action_log :return_amount:: numeric / pow(10,8)
|
||||
ELSE action_log :return_amount:: numeric / pow(10,6)
|
||||
END AS return_amount,
|
||||
action_log :ask_asset::STRING AS return_currency,
|
||||
action_contract_address::STRING AS contract_address
|
||||
FROM {{ ref('silver_classic__event_actions') }} a
|
||||
LEFT JOIN {{ ref('silver_classic__msgs') }} m
|
||||
ON a.tx_id = m.tx_id AND a.msg_index = m.msg_index
|
||||
WHERE action_method = 'swap'
|
||||
AND action_log :maker_fee_amount IS NOT NULL
|
||||
|
||||
),
|
||||
|
||||
source_address_labels AS (
|
||||
SELECT
|
||||
*
|
||||
FROM {{ ref('silver_classic__address_labels') }}
|
||||
),
|
||||
|
||||
astro_pairs AS (
|
||||
SELECT
|
||||
event_attributes :pair_contract_addr::STRING AS contract_address
|
||||
FROM {{ ref('silver_classic__msg_events') }}
|
||||
WHERE tx_id IN (SELECT
|
||||
tx_id
|
||||
FROM {{ ref('silver_classic__msgs') }}
|
||||
WHERE msg_value :execute_msg :create_pair IS NOT NULL
|
||||
AND msg_value :contract = 'terra1fnywlw4edny3vw44x04xd67uzkdqluymgreu7g'
|
||||
)
|
||||
AND event_type = 'from_contract'
|
||||
)
|
||||
|
||||
SELECT DISTINCT
|
||||
e.blockchain,
|
||||
chain_id,
|
||||
block_id,
|
||||
msg_index,
|
||||
tx_index,
|
||||
e.block_timestamp,
|
||||
e.tx_id,
|
||||
sender,
|
||||
offer_amount,
|
||||
CASE
|
||||
WHEN offer_currency = 'terra1mddcdx0ujx89f38gu7zspk2r2ffdl5enyz2u03' THEN offer_amount * o.price * 100
|
||||
ELSE offer_amount * o.price
|
||||
END AS offer_amount_usd,
|
||||
offer_currency,
|
||||
return_amount,
|
||||
CASE
|
||||
WHEN return_currency = 'terra1mddcdx0ujx89f38gu7zspk2r2ffdl5enyz2u03' THEN return_amount * r.price * 100
|
||||
ELSE return_amount * r.price
|
||||
END AS return_amount_usd,
|
||||
return_currency,
|
||||
e.contract_address AS pool_address,
|
||||
coalesce(l.address_name, d.symbol) AS pool_name
|
||||
FROM
|
||||
source_event_actions e
|
||||
|
||||
LEFT OUTER JOIN prices o
|
||||
ON DATE_TRUNC('hour',e.block_timestamp) = o.hour
|
||||
AND e.offer_currency = o.currency
|
||||
|
||||
LEFT OUTER JOIN prices r
|
||||
ON DATE_TRUNC('hour',e.block_timestamp) = r.hour
|
||||
AND e.return_currency = r.currency
|
||||
|
||||
LEFT OUTER JOIN source_address_labels l
|
||||
ON e.contract_address = l.address
|
||||
AND l.blockchain = 'terra'
|
||||
AND l.creator = 'flipside'
|
||||
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__dex_contracts') }} d
|
||||
ON e.contract_address = d.contract_address
|
||||
WHERE offer_amount IS NOT NULL
|
||||
AND offer_currency IS NOT NULL
|
||||
|
||||
53
models/gold/classic/classic__ez_astroport_swaps.yml
Normal file
53
models/gold/classic/classic__ez_astroport_swaps.yml
Normal file
@ -0,0 +1,53 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: classic__ez_astroport_swaps
|
||||
descriptions: |-
|
||||
This table records Astroport swaps executed by smart contracts in Astroport liquidity pools.
|
||||
|
||||
columns:
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id') }}"
|
||||
|
||||
- name: MSG_INDEX
|
||||
description: Message index
|
||||
|
||||
- name: TX_INDEX
|
||||
description: Transaction event index
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
|
||||
- name: BLOCKCHAIN
|
||||
description: "{{ doc('blockchain') }}"
|
||||
|
||||
- name: CHAIN_ID
|
||||
description: "{{ doc('chain_id') }}"
|
||||
|
||||
- name: TX_ID
|
||||
description: "{{ doc('tx_id') }}"
|
||||
|
||||
- name: OFFER_CURRENCY
|
||||
description: "{{ doc('from_currency') }}"
|
||||
|
||||
- name: SENDER
|
||||
description: "{{ doc('trader') }}"
|
||||
|
||||
- name: OFFER_AMOUNT
|
||||
description: "{{ doc('from_amount') }}"
|
||||
|
||||
- name: OFFER_AMOUNT_USD
|
||||
description: The amount that the user sent to be swapped for another currency, in USD.
|
||||
|
||||
- name: RETURN_AMOUNT
|
||||
description: The amount returned to the sender
|
||||
|
||||
- name: RETURN_CURRENCY
|
||||
description: The currency returned to the sender
|
||||
|
||||
- name: RETURN_AMOUNT_USD
|
||||
description: The amount returned to the sender, in USD.
|
||||
|
||||
- name: POOL_ADDRESS
|
||||
description: "{{ doc('liquidity_pool_address') }}"
|
||||
- name: POOL_NAME
|
||||
description: "{{ doc('label') }}"
|
||||
22
models/gold/classic/classic__ez_event_actions.sql
Normal file
22
models/gold/classic/classic__ez_event_actions.sql
Normal file
@ -0,0 +1,22 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
secure = 'true',
|
||||
tags = ['snowflake', 'classic', 'event_actions', 'terra']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_id,
|
||||
block_timestamp,
|
||||
a.blockchain,
|
||||
chain_id,
|
||||
tx_id,
|
||||
action_index,
|
||||
msg_index,
|
||||
action_contract_address,
|
||||
l.address_name AS contract_label,
|
||||
action_method,
|
||||
action_log
|
||||
FROM
|
||||
{{ ref('silver_classic__event_actions') }} a
|
||||
LEFT OUTER JOIN {{ ref('silver_classic__address_labels') }} AS l
|
||||
ON action_contract_address = l.address AND l.blockchain = 'terra' AND l.creator = 'flipside'
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user