diff --git a/models/descriptions/__overview__.md b/models/descriptions/__overview__.md index 0b812ec..910ab5f 100644 --- a/models/descriptions/__overview__.md +++ b/models/descriptions/__overview__.md @@ -21,6 +21,7 @@ There is more information on how to use dbt docs in the last section of this doc **Dimension Tables:** - [core.dim_labels](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.core__dim_labels) - [core.dim_programs](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.core__dim_programs) +- [core.dim_token_registrations](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.core__dim_token_registrations) **Fact Tables:** - [core.fact_block_round_batches](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.core__fact_block_round_batches) @@ -30,6 +31,11 @@ There is more information on how to use dbt docs in the last section of this doc - [core.fact_transitions](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.core__fact_transitions) - [core.fact_transfers](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.core__fact_transfers) +### DeFi Tables (`aleo`.`DEFI`.``) + +**Fact Tables:** +- [defi.fact_swaps](https://flipsidecrypto.github.io/aleo-models/#!/model/model.aleo_models.defi__fact_swaps) + ### Price Tables (`aleo`.`PRICE`.``) **Dimension Tables:** diff --git a/models/gold/core/core__dim_token_registrations.sql b/models/gold/core/core__dim_token_registrations.sql new file mode 100644 index 0000000..6389337 --- /dev/null +++ b/models/gold/core/core__dim_token_registrations.sql @@ -0,0 +1,38 @@ +{{ config( + materialized = 'incremental', + unique_key = ['dim_token_registrations_id'], + incremental_strategy = 'merge', + merge_exclude_columns = ['inserted_timestamp'], + tags = ['core','full_test'] +) }} + +SELECT + tx_id, + block_id, + block_timestamp, + token_id, + decode_u128_to_ascii(name_encoded) as token_name, + decode_u128_to_ascii(symbol_encoded) as symbol, + decimals, + max_supply, + external_auth_required, + external_auth_party, + name_encoded, + symbol_encoded, + {{ dbt_utils.generate_surrogate_key( + ['token_id'] + ) }} AS dim_token_registrations_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS invocation_id +FROM + {{ ref('silver__token_registrations') }} + +{% if is_incremental() %} +WHERE + modified_timestamp >= ( + SELECT + MAX(modified_timestamp) + FROM {{ this }} + ) +{% endif %} \ No newline at end of file diff --git a/models/gold/core/core__dim_token_registrations.yml b/models/gold/core/core__dim_token_registrations.yml new file mode 100644 index 0000000..f48fcea --- /dev/null +++ b/models/gold/core/core__dim_token_registrations.yml @@ -0,0 +1,81 @@ +version: 2 + +models: + - name: core__dim_token_registrations + description: Dimension table containing information about token registrations on the network. + columns: + - name: TX_ID + description: "{{ doc('tx_id') }}" + tests: + - dbt_expectations.expect_column_to_exist + + - name: BLOCK_ID + description: "{{ doc('block_id') }}" + tests: + - dbt_expectations.expect_column_to_exist + + - name: BLOCK_TIMESTAMP + description: "{{ doc('block_timestamp') }}" + tests: + - dbt_expectations.expect_column_to_exist + + - name: TOKEN_ID + description: "The ID of the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: TOKEN_NAME + description: "The decoded name of the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: SYMBOL + description: "The decoded symbol of the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: DECIMALS + description: "The number of decimal places for the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: MAX_SUPPLY + description: "The maximum supply of the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: EXTERNAL_AUTH_REQUIRED + description: "Flag indicating if external authorization is required" + tests: + - dbt_expectations.expect_column_to_exist + + - name: EXTERNAL_AUTH_PARTY + description: "The party responsible for external authorization, if required" + tests: + - dbt_expectations.expect_column_to_exist + + - name: NAME_ENCODED + description: "The original encoded name of the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: SYMBOL_ENCODED + description: "The original encoded symbol of the token" + tests: + - dbt_expectations.expect_column_to_exist + + - name: DIM_TOKEN_REGISTRATIONS_ID + description: '{{ doc("pk") }}' + tests: + - unique + - not_null + + - name: INSERTED_TIMESTAMP + description: '{{ doc("inserted_timestamp") }}' + tests: + - not_null + + - name: MODIFIED_TIMESTAMP + description: '{{ doc("modified_timestamp") }}' + tests: + - not_null diff --git a/models/silver/tokens/silver__token_registrations.sql b/models/silver/tokens/silver__token_registrations.sql deleted file mode 100644 index a4dd5fa..0000000 --- a/models/silver/tokens/silver__token_registrations.sql +++ /dev/null @@ -1,97 +0,0 @@ -{{ config( - materialized = 'table', - tags = ['noncore', 'full_test'] -) }} - -with base_data as ( - select - tx_id, - block_id, - block_timestamp, - inputs - from aleo_dev.core.fact_transitions - where program_id = 'token_registry.aleo' - and function = 'register_token' - and succeeded -), - -flattened_inputs as ( - select - tx_id, - block_id, - block_timestamp, - value:id::string as id, - value:value::string as value, - row_number() over (partition by tx_id order by index) - 1 as input_index - from base_data, - lateral flatten(input => inputs) -), - -parsed_inputs as ( - select - tx_id, - block_id, - block_timestamp, - max(case when input_index = 0 then value end) as token_id_raw, - max(case when input_index = 1 then value end) as name_raw, - max(case when input_index = 2 then value end) as symbol_raw, - max(case when input_index = 3 then value end) as decimals_raw, - max(case when input_index = 4 then value end) as max_supply_raw, - max(case when input_index = 5 then value end) as external_auth_required_raw, - max(case when input_index = 6 then value end) as external_auth_party - from flattened_inputs - where block_id != 186732 - group by tx_id, block_id, block_timestamp - - union all - - select - tx_id, - block_id, - block_timestamp, - max(case when input_index = 1 then value end) as token_id_raw, - max(case when input_index = 3 then value end) as name_raw, - max(case when input_index = 5 then value end) as symbol_raw, - max(case when input_index = 6 then value end) as decimals_raw, - max(case when input_index = 8 then value end) as max_supply_raw, - max(case when input_index = 10 then value end) as external_auth_required_raw, - max(case when input_index = 12 then value end) as external_auth_party - from flattened_inputs - where block_id = 186732 -- exceptional pondo token from early mainnet - group by tx_id, block_id, block_timestamp -), -cleaned_strings as ( - select - tx_id, - block_id, - block_timestamp, - split_part(token_id_raw, 'field', 1) as token_id, - split_part(name_raw, 'u', 1) as name_encoded, - split_part(symbol_raw, 'u', 1) as symbol_encoded, - split_part(decimals_raw, 'u', 1) as decimals, - split_part(max_supply_raw, 'u', 1) as max_supply, - external_auth_required_raw :: boolean as external_auth_required, - external_auth_party - from - parsed_inputs -) -select - tx_id, - block_id, - block_timestamp, - token_id, - decode_u128_to_ascii(name_encoded) as token_name, - decode_u128_to_ascii(symbol_encoded) as symbol, - decimals, - max_supply, - external_auth_required, - external_auth_party, - name_encoded, - symbol_encoded, - {{ dbt_utils.generate_surrogate_key( - ['tx_id', 'token_name'] - ) }} AS tokens_id, - SYSDATE() as inserted_timestamp, - SYSDATE() as modified_timestamp, - '{{ invocation_id }}' AS _invocation_id -from cleaned_strings diff --git a/models/silver/tokens/silver__token_registrations.yml b/models/silver/tokens/silver__token_registrations.yml deleted file mode 100644 index 7debf97..0000000 --- a/models/silver/tokens/silver__token_registrations.yml +++ /dev/null @@ -1,56 +0,0 @@ -version: 2 - -models: - - name: silver__token_registrations - - columns: - - name: tx_id - tests: - - not_null - - - name: block_id - tests: - - not_null - - - name: block_timestamp - tests: - - not_null - - - name: token_id - tests: - - not_null - - - name: token_name - tests: - - not_null - - - name: symbol - tests: - - not_null - - - name: decimals - tests: - - not_null - - - name: max_supply - tests: - - not_null - - - name: external_auth_required - tests: - - not_null - - - name: external_auth_party - - - name: name_encoded - tests: - - not_null - - - name: symbol_encoded - tests: - - not_null - - - name: tokens_id - tests: - - unique - - not_null \ No newline at end of file