From 6e64c2bc77218d12684f8393da5ecfeac074b37d Mon Sep 17 00:00:00 2001 From: Mike Stepanovic Date: Thu, 30 Jan 2025 14:04:18 -0700 Subject: [PATCH] added all gold models, plus enhanced (EZ) operations and docs --- docs/field_descriptions.md | 2 +- models/gold/core/dim__assets.sql | 4 +- models/gold/core/dim__assets.yml | 19 +- models/gold/core/fact__accounts.sql | 3 +- models/gold/core/fact__accounts.yml | 64 ++-- models/gold/core/fact__ledgers.sql | 1 + models/gold/core/fact__liquidity_pools.sql | 3 +- models/gold/core/fact__liquidity_pools.yml | 58 ++- models/gold/core/fact__operations.sql | 3 +- models/gold/core/fact__operations.yml | 303 ++++++++-------- models/gold/core/fact__trades.sql | 50 +++ models/gold/core/fact__trades.yml | 135 +++++++ models/gold/core/fact__transactions.sql | 74 ++++ models/gold/core/fact__transactions.yml | 192 ++++++++++ models/gold/operations/ez_operations.sql | 394 +++++++++++++++++++++ models/gold/operations/ez_operations.yml | 115 ++++++ 16 files changed, 1193 insertions(+), 227 deletions(-) create mode 100644 models/gold/core/fact__trades.sql create mode 100644 models/gold/core/fact__trades.yml create mode 100644 models/gold/core/fact__transactions.sql create mode 100644 models/gold/core/fact__transactions.yml create mode 100644 models/gold/operations/ez_operations.sql create mode 100644 models/gold/operations/ez_operations.yml diff --git a/docs/field_descriptions.md b/docs/field_descriptions.md index 1095abe..2c96e83 100644 --- a/docs/field_descriptions.md +++ b/docs/field_descriptions.md @@ -726,7 +726,7 @@ JSON record containing operation-specific details. {# Asset-specific fields #} -{% docs asset_id_hash %} +{% docs asset_id %} The Farm Hash encoding of Asset Code + Asset Issuer + Asset Type. This field is optimized for cross table joins since integer joins are less expensive than the original asset id components. {% enddocs %} diff --git a/models/gold/core/dim__assets.sql b/models/gold/core/dim__assets.sql index ae0f82c..841a7ca 100644 --- a/models/gold/core/dim__assets.sql +++ b/models/gold/core/dim__assets.sql @@ -1,3 +1,4 @@ +-- depends_on: {{ ref('silver__assets') }} {{ config( materialized = 'incremental', unique_key = ['dim_assets_id'], @@ -7,10 +8,11 @@ ) }} SELECT + id, asset_type, asset_code, asset_issuer, - asset_id as asset_id_hash, + asset_id, {{ dbt_utils.generate_surrogate_key( ['asset_id'] ) }} AS dim_assets_id, diff --git a/models/gold/core/dim__assets.yml b/models/gold/core/dim__assets.yml index c86a512..7d05e5b 100644 --- a/models/gold/core/dim__assets.yml +++ b/models/gold/core/dim__assets.yml @@ -4,6 +4,12 @@ models: - name: dim__assets description: Dimension table containing information about assets on the network. columns: + - name: ID + description: '{{ doc("id") }}' + tests: + - dbt_expectations.expect_column_to_exist + - not_null + - name: ASSET_TYPE description: '{{ doc("asset_type") }}' tests: @@ -20,8 +26,8 @@ models: tests: - dbt_expectations.expect_column_to_exist - - name: ASSET_ID_HASH - description: '{{ doc("asset_id_hash") }}' + - name: ASSET_ID + description: '{{ doc("asset_id") }}' tests: - dbt_expectations.expect_column_to_exist - not_null @@ -43,10 +49,13 @@ models: tests: - not_null - - name: _INVOCATION_ID - description: "Unique identifier of the dbt job that inserted or modified this record" + - name: FACT_ASSET_ID + description: '{{ doc("pk") }}' + tests: + - dbt_expectations.expect_column_to_exist + - not_null tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - ASSET_ID + - asset_id diff --git a/models/gold/core/fact__accounts.sql b/models/gold/core/fact__accounts.sql index fa0756d..e83ed95 100644 --- a/models/gold/core/fact__accounts.sql +++ b/models/gold/core/fact__accounts.sql @@ -1,3 +1,4 @@ +-- depends_on: {{ ref('silver__accounts') }} {{ config( materialized = 'incremental', unique_key = ["account_id","closed_at"], @@ -31,7 +32,7 @@ SELECT sequence_time, closed_at, ledger_sequence, - {{ dbt_utils.generate_surrogate_key(['account_id', 'closed_at']) }} AS core_accounts_id, + {{ dbt_utils.generate_surrogate_key(['account_id', 'closed_at']) }} AS fact_accounts_id, SYSDATE() AS inserted_timestamp, SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id diff --git a/models/gold/core/fact__accounts.yml b/models/gold/core/fact__accounts.yml index 3b3cbcb..2b972ed 100644 --- a/models/gold/core/fact__accounts.yml +++ b/models/gold/core/fact__accounts.yml @@ -4,136 +4,136 @@ models: - name: core__accounts description: Core fact table containing all Stellar account information and their current states columns: - - name: account_id + - name: ACCOUNT_ID description: '{{ doc("account_id") }}' tests: - not_null - - name: balance + - name: BALANCE description: '{{ doc("balance") }}' tests: - not_null - - name: buying_liabilities + - name: BUYING_LIABILITIES description: '{{ doc("buying_liabilities") }}' tests: - not_null - - name: selling_liabilities + - name: SELLING_LIABILITIES description: '{{ doc("selling_liabilities") }}' tests: - not_null - - name: sequence_number + - name: SEQUENCE_NUMBER description: '{{ doc("sequence_number") }}' tests: - not_null - - name: num_subentries + - name: NUM_SUBENTRIES description: '{{ doc("num_subentries") }}' tests: - not_null - - name: inflation_destination + - name: INFLATION_DESTINATION description: '{{ doc("inflation_destination") }}' - - name: flags + - name: FLAGS description: '{{ doc("flags") }}' tests: - not_null - - name: home_domain + - name: HOME_DOMAIN description: '{{ doc("home_domain") }}' - - name: master_weight + - name: MASTER_WEIGHT description: '{{ doc("master_weight") }}' tests: - not_null - - name: threshold_low + - name: THRESHOLD_LOW description: '{{ doc("threshold_low") }}' tests: - not_null - - name: threshold_medium + - name: THRESHOLD_MEDIUM description: '{{ doc("threshold_medium") }}' tests: - not_null - - name: threshold_high + - name: THRESHOLD_HIGH description: '{{ doc("threshold_high") }}' tests: - not_null - - name: last_modified_ledger + - name: LAST_MODIFIED_LEDGER description: '{{ doc("last_modified_ledger") }}' tests: - not_null - - name: ledger_entry_change + - name: LEDGER_ENTRY_CHANGE description: '{{ doc("ledger_entry_change") }}' tests: - not_null - - name: deleted + - name: DELETED description: '{{ doc("deleted") }}' tests: - not_null - - name: batch_id + - name: BATCH_ID description: '{{ doc("batch_id") }}' - - name: batch_run_date + - name: BATCH_RUN_DATE description: '{{ doc("batch_run_date") }}' - - name: batch_insert_ts + - name: BATCH_INSERT_TS description: '{{ doc("batch_insert_ts") }}' - - name: sponsor + - name: SPONSOR description: '{{ doc("sponsor") }}' - - name: num_sponsored + - name: NUM_SPONSORED description: '{{ doc("num_sponsored") }}' tests: - not_null - - name: num_sponsoring + - name: NUM_SPONSORING description: '{{ doc("num_sponsoring") }}' tests: - not_null - - name: sequence_ledger + - name: SEQUENCE_LEDGER description: '{{ doc("sequence_ledger") }}' tests: - not_null - - name: sequence_time + - name: SEQUENCE_TIME description: '{{ doc("sequence_time") }}' tests: - not_null - - name: closed_at + - name: CLOSED_AT description: '{{ doc("closed_at") }}' tests: - not_null - - name: ledger_sequence + - name: LEDGER_SEQUENCE description: '{{ doc("ledger_sequence") }}' tests: - not_null - - name: core_accounts_id - description: '{{ doc("core_accounts_id") }}' + - name: FACT_ACCOUNTS_ID + description: '{{ doc("pk") }}' tests: - unique - not_null - - name: inserted_timestamp + - name: INSERTED_TIMESTAMP description: '{{ doc("inserted_timestamp") }}' tests: - not_null - - name: modified_timestamp + - name: MODIFIED_TIMESTAMP description: '{{ doc("modified_timestamp") }}' tests: - not_null @@ -141,5 +141,5 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: - - account_id - - closed_at \ No newline at end of file + - ACCOUNT_ID + - CLOSED_AT \ No newline at end of file diff --git a/models/gold/core/fact__ledgers.sql b/models/gold/core/fact__ledgers.sql index 0ebbfed..3eecaea 100644 --- a/models/gold/core/fact__ledgers.sql +++ b/models/gold/core/fact__ledgers.sql @@ -1,3 +1,4 @@ +-- depends_on: {{ ref('silver__ledgers') }} {{ config( materialized = 'incremental', unique_key = ['fact_ledgers_id'], diff --git a/models/gold/core/fact__liquidity_pools.sql b/models/gold/core/fact__liquidity_pools.sql index 11cc792..2af6923 100644 --- a/models/gold/core/fact__liquidity_pools.sql +++ b/models/gold/core/fact__liquidity_pools.sql @@ -9,7 +9,6 @@ ) }} SELECT - partition_id, liquidity_pool_id, type, fee, @@ -36,7 +35,7 @@ SELECT _inserted_timestamp, {{ dbt_utils.generate_surrogate_key( ['liquidity_pool_id', 'closed_at'] - ) }} AS liquidity_pools_id, + ) }} AS fact_liquidity_pools_id, SYSDATE() AS inserted_timestamp, SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id diff --git a/models/gold/core/fact__liquidity_pools.yml b/models/gold/core/fact__liquidity_pools.yml index 528d570..589df24 100644 --- a/models/gold/core/fact__liquidity_pools.yml +++ b/models/gold/core/fact__liquidity_pools.yml @@ -5,104 +5,102 @@ models: description: Fact table containing liquidity pool data including pool details, asset pairs, and metrics. columns: - - name: partition_id - description: '{{ doc("partition_id") }}' - - name: liquidity_pool_id + - name: LIQUIDITY_POOL_ID description: '{{ doc("liquidity_pool_id") }}' tests: - not_null - - name: type + - name: TYPE description: '{{ doc("type") }}' - - name: fee + - name: FEE description: '{{ doc("fee") }}' - - name: trustline_count + - name: TRUSTLINE_COUNT description: '{{ doc("trustline_count") }}' - - name: pool_share_count + - name: POOL_SHARE_COUNT description: '{{ doc("pool_share_count") }}' - - name: asset_a_type + - name: ASSET_A_TYPE description: '{{ doc("asset_type") }}' - - name: asset_a_code + - name: ASSET_A_CODE description: '{{ doc("asset_code") }}' - - name: asset_a_issuer + - name: ASSET_A_ISSUER description: '{{ doc("asset_issuer") }}' - - name: asset_a_id + - name: ASSET_A_ID description: '{{ doc("asset_id") }}' - - name: asset_a_amount + - name: ASSET_A_AMOUNT description: '{{ doc("asset_a_amount") }}' - - name: asset_b_type + - name: ASSET_B_TYPE description: '{{ doc("asset_type") }}' - - name: asset_b_code + - name: ASSET_B_CODE description: '{{ doc("asset_code") }}' - - name: asset_b_issuer + - name: ASSET_B_ISSUER description: '{{ doc("asset_issuer") }}' - - name: asset_b_id + - name: ASSET_B_ID description: '{{ doc("asset_id") }}' - - name: asset_b_amount + - name: ASSET_B_AMOUNT description: '{{ doc("asset_b_amount") }}' - - name: last_modified_ledger + - name: LAST_MODIFIED_LEDGER description: '{{ doc("last_modified_ledger") }}' - - name: ledger_entry_change + - name: LEDGER_ENTRY_CHANGE description: '{{ doc("ledger_entry_change") }}' - - name: deleted + - name: DELETED description: '{{ doc("deleted") }}' - - name: batch_id + - name: BATCH_ID description: '{{ doc("batch_id") }}' - - name: batch_run_date + - name: BATCH_RUN_DATE description: '{{ doc("batch_run_date") }}' - - name: batch_insert_ts + - name: BATCH_INSERT_TS description: '{{ doc("batch_insert_ts") }}' - - name: closed_at + - name: CLOSED_AT description: '{{ doc("closed_at") }}' tests: - not_null - - name: ledger_sequence + - name: LEDGER_SEQUENCE description: '{{ doc("ledger_sequence") }}' - - name: _inserted_timestamp + - name: _INSERTED_TIMESTAMP description: '{{ doc("inserted_timestamp") }}' tests: - not_null - - name: liquidity_pools_id + - name: LIQUIDITY_POOLS_ID description: '{{ doc("liquidity_pools_id") }}' tests: - unique - not_null - - name: inserted_timestamp + - name: INSERTED_TIMESTAMP description: '{{ doc("inserted_timestamp") }}' tests: - not_null - - name: modified_timestamp + - name: MODIFIED_TIMESTAMP description: '{{ doc("modified_timestamp") }}' tests: - not_null - - name: _invocation_id + - name: _INVOCATION_ID description: '{{ doc("invocation_id") }}' tests: - not_null diff --git a/models/gold/core/fact__operations.sql b/models/gold/core/fact__operations.sql index 2a7ed5d..db85e19 100644 --- a/models/gold/core/fact__operations.sql +++ b/models/gold/core/fact__operations.sql @@ -9,7 +9,6 @@ ) }} SELECT - partition_id, op_id, account, amount, @@ -154,7 +153,7 @@ SELECT op_application_order, txn_application_order, _inserted_timestamp, - {{ dbt_utils.generate_surrogate_key(['op_id']) }} AS operations_id, + {{ dbt_utils.generate_surrogate_key(['op_id']) }} AS fact_operations_id, SYSDATE() AS inserted_timestamp, SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id diff --git a/models/gold/core/fact__operations.yml b/models/gold/core/fact__operations.yml index 708907b..aacd487 100644 --- a/models/gold/core/fact__operations.yml +++ b/models/gold/core/fact__operations.yml @@ -4,449 +4,446 @@ models: - name: fact__operations description: A comprehensive view of all operations executed on the Stellar network, including transaction details, operation types, and their outcomes. columns: - - name: partition_id - description: '{{ doc("partition_id") }}' - - - name: op_id + - name: OP_ID description: '{{ doc("op_id") }}' tests: - unique - not_null - - name: account + - name: ACCOUNT description: '{{ doc("account") }}' - - name: amount + - name: AMOUNT description: '{{ doc("amount") }}' - - name: asset_code + - name: ASSET_CODE description: '{{ doc("asset_code") }}' - - name: asset_issuer + - name: ASSET_ISSUER description: '{{ doc("asset_issuer") }}' - - name: asset_type + - name: ASSET_TYPE description: '{{ doc("asset_type") }}' - - name: asset_id + - name: ASSET_ID description: '{{ doc("asset_id") }}' - - name: authorize + - name: AUTHORIZE description: '{{ doc("authorize") }}' - - name: balance_id + - name: BALANCE_ID description: '{{ doc("balance_id") }}' - - name: buying_asset_code + - name: BUYING_ASSET_CODE description: '{{ doc("buying_asset_code") }}' - - name: buying_asset_issuer + - name: BUYING_ASSET_ISSUER description: '{{ doc("buying_asset_issuer") }}' - - name: buying_asset_type + - name: BUYING_ASSET_TYPE description: '{{ doc("buying_asset_type") }}' - - name: buying_asset_id + - name: BUYING_ASSET_ID description: '{{ doc("buying_asset_id") }}' - - name: from + - name: FROM description: '{{ doc("from") }}' - - name: funder + - name: FUNDER description: '{{ doc("funder") }}' - - name: high_threshold + - name: HIGH_THRESHOLD description: '{{ doc("threshold_high") }}' - - name: home_domain + - name: HOME_DOMAIN description: '{{ doc("home_domain") }}' - - name: inflation_dest + - name: INFLATION_DEST description: '{{ doc("inflation_destination") }}' - - name: into + - name: INTO description: '{{ doc("into") }}' - - name: limit + - name: LIMIT description: '{{ doc("limit") }}' - - name: low_threshold + - name: LOW_THRESHOLD description: '{{ doc("threshold_low") }}' - - name: master_key_weight + - name: MASTER_KEY_WEIGHT description: '{{ doc("master_weight") }}' - - name: med_threshold + - name: MED_THRESHOLD description: '{{ doc("threshold_medium") }}' - - name: name + - name: NAME description: '{{ doc("name") }}' - - name: offer_id + - name: OFFER_ID description: '{{ doc("offer_id") }}' - - name: path + - name: PATH description: '{{ doc("path") }}' - - name: price + - name: PRICE description: '{{ doc("price") }}' - - name: d + - name: D description: '{{ doc("d") }}' - - name: n + - name: N description: '{{ doc("n") }}' - - name: selling_asset_code + - name: SELLING_ASSET_CODE description: '{{ doc("selling_asset_code") }}' - - name: selling_asset_issuer + - name: SELLING_ASSET_ISSUER description: '{{ doc("selling_asset_issuer") }}' - - name: selling_asset_type + - name: SELLING_ASSET_TYPE description: '{{ doc("selling_asset_type") }}' - - name: selling_asset_id + - name: SELLING_ASSET_ID description: '{{ doc("selling_asset_id") }}' - - name: set_flags + - name: SET_FLAGS description: '{{ doc("set_flags") }}' - - name: set_flags_s + - name: SET_FLAGS_S description: '{{ doc("set_flags_s") }}' - - name: signer_key + - name: SIGNER_KEY description: '{{ doc("signer_key") }}' - - name: signer_weight + - name: SIGNER_WEIGHT description: '{{ doc("signer_weight") }}' - - name: source_amount + - name: SOURCE_AMOUNT description: '{{ doc("source_amount") }}' - - name: source_asset_code + - name: SOURCE_ASSET_CODE description: '{{ doc("source_asset_code") }}' - - name: source_asset_issuer + - name: SOURCE_ASSET_ISSUER description: '{{ doc("source_asset_issuer") }}' - - name: source_asset_type + - name: SOURCE_ASSET_TYPE description: '{{ doc("source_asset_type") }}' - - name: source_asset_id + - name: SOURCE_ASSET_ID description: '{{ doc("source_asset_id") }}' - - name: source_max + - name: SOURCE_MAX description: '{{ doc("source_max") }}' - - name: starting_balance + - name: STARTING_BALANCE description: '{{ doc("starting_balance") }}' - - name: to + - name: TO description: '{{ doc("to") }}' - - name: trustee + - name: TRUSTEE description: '{{ doc("trustee") }}' - - name: trustor + - name: TRUSTOR description: '{{ doc("trustor") }}' - - name: trustline_asset + - name: TRUSTLINE_ASSET description: '{{ doc("trustline_asset") }}' - - name: value + - name: VALUE description: '{{ doc("value") }}' - - name: clear_flags + - name: CLEAR_FLAGS description: '{{ doc("clear_flags") }}' - - name: clear_flags_s + - name: CLEAR_FLAGS_S description: '{{ doc("clear_flags_s") }}' - - name: destination_min + - name: DESTINATION_MIN description: '{{ doc("destination_min") }}' - - name: bump_to + - name: BUMP_TO description: '{{ doc("bump_to") }}' - - name: sponsor + - name: SPONSOR description: '{{ doc("sponsor") }}' - - name: sponsored_id + - name: SPONSORED_ID description: '{{ doc("sponsored_id") }}' - - name: begin_sponsor + - name: BEGIN_SPONSOR description: '{{ doc("begin_sponsor") }}' - - name: authorize_to_maintain_liabilities + - name: AUTHORIZE_TO_MAINTAIN_LIABILITIES description: '{{ doc("authorize_to_maintain_liabilities") }}' - - name: clawback_enabled + - name: CLAWBACK_ENABLED description: '{{ doc("clawback_enabled") }}' - - name: liquidity_pool_id + - name: LIQUIDITY_POOL_ID description: '{{ doc("liquidity_pool_id") }}' - - name: reserve_a_asset_type + - name: RESERVE_A_ASSET_TYPE description: '{{ doc("reserve_a_asset_type") }}' - - name: reserve_a_asset_id + - name: RESERVE_A_ASSET_ID description: '{{ doc("reserve_a_asset_id") }}' - - name: reserve_a_asset_code + - name: RESERVE_A_ASSET_CODE description: '{{ doc("reserve_a_asset_code") }}' - - name: reserve_a_asset_issuer + - name: RESERVE_A_ASSET_ISSUER description: '{{ doc("reserve_a_asset_issuer") }}' - - name: reserve_a_max_amount + - name: RESERVE_A_MAX_AMOUNT description: '{{ doc("reserve_a_max_amount") }}' - - name: reserve_a_deposit_amount + - name: RESERVE_A_DEPOSIT_AMOUNT description: '{{ doc("reserve_a_deposit_amount") }}' - - name: reserve_b_asset_type + - name: RESERVE_B_ASSET_TYPE description: '{{ doc("reserve_b_asset_type") }}' - - name: reserve_b_asset_id + - name: RESERVE_B_ASSET_ID description: '{{ doc("reserve_b_asset_id") }}' - - name: reserve_b_asset_code + - name: RESERVE_B_ASSET_CODE description: '{{ doc("reserve_b_asset_code") }}' - - name: reserve_b_asset_issuer + - name: RESERVE_B_ASSET_ISSUER description: '{{ doc("reserve_b_asset_issuer") }}' - - name: reserve_b_max_amount + - name: RESERVE_B_MAX_AMOUNT description: '{{ doc("reserve_b_max_amount") }}' - - name: reserve_b_deposit_amount + - name: RESERVE_B_DEPOSIT_AMOUNT description: '{{ doc("reserve_b_deposit_amount") }}' - - name: min_price - description: '{{ doc("min_price") }}' + - name: MIN_PRICE_R + description: '{{ doc("min_price_r") }}' - - name: max_price - description: '{{ doc("max_price") }}' + - name: MAX_PRICE_R + description: '{{ doc("max_price_r") }}' - - name: shares_received + - name: SHARES_RECEIVED description: '{{ doc("shares_received") }}' - - name: reserve_a_min_amount + - name: RESERVE_A_MIN_AMOUNT description: '{{ doc("reserve_a_min_amount") }}' - - name: reserve_b_min_amount + - name: RESERVE_B_MIN_AMOUNT description: '{{ doc("reserve_b_min_amount") }}' - - name: shares + - name: SHARES description: '{{ doc("shares") }}' - - name: reserve_a_withdraw_amount + - name: RESERVE_A_WITHDRAW_AMOUNT description: '{{ doc("reserve_a_withdraw_amount") }}' - - name: reserve_b_withdraw_amount + - name: RESERVE_B_WITHDRAW_AMOUNT description: '{{ doc("reserve_b_withdraw_amount") }}' - - name: op_source_account + - name: OP_SOURCE_ACCOUNT description: '{{ doc("op_source_account") }}' - - name: op_source_account_muxed + - name: OP_SOURCE_ACCOUNT_MUXED description: '{{ doc("op_source_account_muxed") }}' - - name: transaction_id + - name: TRANSACTION_ID description: '{{ doc("transaction_id") }}' - - name: type + - name: TYPE description: '{{ doc("type") }}' - - name: transaction_hash + - name: TRANSACTION_HASH description: '{{ doc("transaction_hash") }}' - - name: ledger_sequence + - name: LEDGER_SEQUENCE description: '{{ doc("ledger_sequence") }}' - - name: txn_account + - name: TXN_ACCOUNT description: '{{ doc("txn_account") }}' - - name: account_sequence + - name: ACCOUNT_SEQUENCE description: '{{ doc("account_sequence") }}' - - name: max_fee + - name: MAX_FEE description: '{{ doc("max_fee") }}' - - name: txn_operation_count + - name: TXN_OPERATION_COUNT description: '{{ doc("txn_operation_count") }}' - - name: txn_created_at + - name: TXN_CREATED_AT description: '{{ doc("txn_created_at") }}' - - name: memo_type + - name: MEMO_TYPE description: '{{ doc("memo_type") }}' - - name: memo + - name: MEMO description: '{{ doc("memo") }}' - - name: time_bounds + - name: TIME_BOUNDS description: '{{ doc("time_bounds") }}' - - name: successful + - name: SUCCESSFUL description: '{{ doc("successful") }}' - - name: fee_charged + - name: FEE_CHARGED description: '{{ doc("fee_charged") }}' - - name: fee_account + - name: FEE_ACCOUNT description: '{{ doc("fee_account") }}' - - name: new_max_fee + - name: NEW_MAX_FEE description: '{{ doc("new_max_fee") }}' - - name: account_muxed + - name: ACCOUNT_MUXED description: '{{ doc("account_muxed") }}' - - name: fee_account_muxed + - name: FEE_ACCOUNT_MUXED description: '{{ doc("fee_account_muxed") }}' - - name: ledger_hash + - name: LEDGER_HASH description: '{{ doc("ledger_hash") }}' - - name: previous_ledger_hash + - name: PREVIOUS_LEDGER_HASH description: '{{ doc("previous_ledger_hash") }}' - - name: transaction_count + - name: TRANSACTION_COUNT description: '{{ doc("transaction_count") }}' - - name: ledger_operation_count + - name: LEDGER_OPERATION_COUNT description: '{{ doc("ledger_operation_count") }}' - - name: closed_at + - name: CLOSED_AT description: '{{ doc("closed_at") }}' - - name: total_coins + - name: TOTAL_COINS description: '{{ doc("total_coins") }}' - - name: fee_pool + - name: FEE_POOL description: '{{ doc("fee_pool") }}' - - name: base_fee + - name: BASE_FEE description: '{{ doc("base_fee") }}' - - name: base_reserve + - name: BASE_RESERVE description: '{{ doc("base_reserve") }}' - - name: max_tx_set_size + - name: MAX_TX_SET_SIZE description: '{{ doc("max_tx_set_size") }}' - - name: protocol_version + - name: PROTOCOL_VERSION description: '{{ doc("protocol_version") }}' - - name: successful_transaction_count + - name: SUCCESSFUL_TRANSACTION_COUNT description: '{{ doc("successful_transaction_count") }}' - - name: failed_transaction_count + - name: FAILED_TRANSACTION_COUNT description: '{{ doc("failed_transaction_count") }}' - - name: batch_id + - name: BATCH_ID description: '{{ doc("batch_id") }}' - - name: batch_run_date + - name: BATCH_RUN_DATE description: '{{ doc("batch_run_date") }}' - - name: batch_insert_ts + - name: BATCH_INSERT_TS description: '{{ doc("batch_insert_ts") }}' - - name: ledger_bounds + - name: LEDGER_BOUNDS description: '{{ doc("ledger_bounds") }}' - - name: min_account_sequence + - name: MIN_ACCOUNT_SEQUENCE description: '{{ doc("min_account_sequence") }}' - - name: min_account_sequence_age + - name: MIN_ACCOUNT_SEQUENCE_AGE description: '{{ doc("min_account_sequence_age") }}' - - name: min_account_sequence_ledger_gap + - name: MIN_ACCOUNT_SEQUENCE_LEDGER_GAP description: '{{ doc("min_account_sequence_ledger_gap") }}' - - name: extra_signers + - name: EXTRA_SIGNERS description: '{{ doc("extra_signers") }}' - - name: asset_balance_changes + - name: ASSET_BALANCE_CHANGES description: '{{ doc("asset_balance_changes") }}' - - name: parameters + - name: PARAMETERS description: '{{ doc("parameters") }}' - - name: parameters_decoded + - name: PARAMETERS_DECODED description: '{{ doc("parameters_decoded") }}' - - name: function + - name: FUNCTION description: '{{ doc("function") }}' - - name: address + - name: ADDRESS description: '{{ doc("address") }}' - - name: soroban_operation_type + - name: SOROBAN_OPERATION_TYPE description: '{{ doc("soroban_operation_type") }}' - - name: extend_to + - name: EXTEND_TO description: '{{ doc("extend_to") }}' - - name: contract_id + - name: CONTRACT_ID description: '{{ doc("contract_id") }}' - - name: contract_code_hash + - name: CONTRACT_CODE_HASH description: '{{ doc("contract_code_hash") }}' - - name: resource_fee + - name: RESOURCE_FEE description: '{{ doc("resource_fee") }}' - - name: soroban_resources_instructions + - name: SOROBAN_RESOURCES_INSTRUCTIONS description: '{{ doc("soroban_resources_instructions") }}' - - name: soroban_resources_read_bytes + - name: SOROBAN_RESOURCES_READ_BYTES description: '{{ doc("soroban_resources_read_bytes") }}' - - name: soroban_resources_write_bytes + - name: SOROBAN_RESOURCES_WRITE_BYTES description: '{{ doc("soroban_resources_write_bytes") }}' - - name: transaction_result_code + - name: TRANSACTION_RESULT_CODE description: '{{ doc("transaction_result_code") }}' - - name: inclusion_fee_bid + - name: INCLUSION_FEE_BID description: '{{ doc("inclusion_fee_bid") }}' - - name: inclusion_fee_charged + - name: INCLUSION_FEE_CHARGED description: '{{ doc("inclusion_fee_charged") }}' - - name: resource_fee_refund + - name: RESOURCE_FEE_REFUND description: '{{ doc("resource_fee_refund") }}' - - name: operation_result_code + - name: OPERATION_RESULT_CODE description: '{{ doc("operation_result_code") }}' - - name: operation_trace_code + - name: OPERATION_TRACE_CODE description: '{{ doc("operation_trace_code") }}' - - name: op_application_order + - name: OP_APPLICATION_ORDER description: '{{ doc("op_application_order") }}' - - name: txn_application_order + - name: TXN_APPLICATION_ORDER description: '{{ doc("txn_application_order") }}' - - name: _inserted_timestamp + - name: _INSERTED_TIMESTAMP description: '{{ doc("inserted_timestamp") }}' - - name: operations_id - description: '{{ doc("operations_id") }}' + - name: FACT_OPERATIONS_ID + description: '{{ doc("fact_operations_id") }}' - - name: inserted_timestamp + - name: INSERTED_TIMESTAMP description: '{{ doc("inserted_timestamp") }}' - - name: modified_timestamp + - name: MODIFIED_TIMESTAMP description: '{{ doc("modified_timestamp") }}' - - name: _invocation_id + - name: _INVOCATION_ID description: '{{ doc("invocation_id") }}' - - name: details_json + - name: DETAILS_JSON description: '{{ doc("details_json") }}' \ No newline at end of file diff --git a/models/gold/core/fact__trades.sql b/models/gold/core/fact__trades.sql new file mode 100644 index 0000000..a7c0c55 --- /dev/null +++ b/models/gold/core/fact__trades.sql @@ -0,0 +1,50 @@ +--depends_on: {{ ref('silver__trades') }} +{{ config( + materialized = 'incremental', + unique_key = ['fact_trades_id'], + incremental_predicates = ["dynamic_range_predicate", "partition_id::date"], + merge_exclude_columns = ["inserted_timestamp"], + cluster_by = ['ledger_closed_at::DATE','partition_id','modified_timestamp::DATE'], + tags = ['core'], +) }} + +SELECT + trades_id, + history_operation_id, + "order", + ledger_closed_at, + selling_account_address, + selling_asset_code, + selling_asset_issuer, + selling_asset_type, + selling_asset_id, + selling_amount, + buying_account_address, + buying_asset_code, + buying_asset_issuer, + buying_asset_type, + buying_asset_id, + buying_amount, + price_n, + price_d, + selling_offer_id, + buying_offer_id, + selling_liquidity_pool_id, + liquidity_pool_fee, + trade_type, + rounding_slippage, + seller_is_exact, + _inserted_timestamp, + {{ dbt_utils.generate_surrogate_key( + ['history_operation_id','"order"'] + ) }} AS fact_trades_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM + {{ ref('silver__trades') }} + +{% if is_incremental() %} +WHERE + _inserted_timestamp > (SELECT MAX(_inserted_timestamp) FROM {{ this }}) +{% endif %} diff --git a/models/gold/core/fact__trades.yml b/models/gold/core/fact__trades.yml new file mode 100644 index 0000000..5603830 --- /dev/null +++ b/models/gold/core/fact__trades.yml @@ -0,0 +1,135 @@ +version: 2 + +models: + - name: fact__trades + description: A fact table containing trade execution details from both the decentralized exchange and liquidity pools. + columns: + - name: trades_id + description: '{{ doc("trades_id") }}' + tests: + - unique + - not_null + + - name: history_operation_id + description: '{{ doc("history_operation_id") }}' + tests: + - not_null + + - name: order + description: '{{ doc("order") }}' + tests: + - not_null + + - name: ledger_closed_at + description: '{{ doc("closed_at") }}' + tests: + - not_null + + - name: selling_account_address + description: '{{ doc("selling_account_address") }}' + tests: + - not_null + + - name: selling_asset_code + description: '{{ doc("selling_asset_code") }}' + + - name: selling_asset_issuer + description: '{{ doc("selling_asset_issuer") }}' + + - name: selling_asset_type + description: '{{ doc("selling_asset_type") }}' + tests: + - not_null + + - name: selling_asset_id + description: '{{ doc("selling_asset_id") }}' + tests: + - not_null + + - name: selling_amount + description: '{{ doc("selling_amount") }}' + tests: + - not_null + + - name: buying_account_address + description: '{{ doc("buying_account_address") }}' + tests: + - not_null + + - name: buying_asset_code + description: '{{ doc("buying_asset_code") }}' + + - name: buying_asset_issuer + description: '{{ doc("buying_asset_issuer") }}' + + - name: buying_asset_type + description: '{{ doc("buying_asset_type") }}' + tests: + - not_null + + - name: buying_asset_id + description: '{{ doc("buying_asset_id") }}' + tests: + - not_null + + - name: buying_amount + description: '{{ doc("buying_amount") }}' + tests: + - not_null + + - name: price_n + description: '{{ doc("price_n") }}' + tests: + - not_null + + - name: price_d + description: '{{ doc("price_d") }}' + tests: + - not_null + + - name: selling_offer_id + description: '{{ doc("selling_offer_id") }}' + + - name: buying_offer_id + description: '{{ doc("buying_offer_id") }}' + + - name: selling_liquidity_pool_id + description: '{{ doc("selling_liquidity_pool_id") }}' + + - name: liquidity_pool_fee + description: '{{ doc("liquidity_pool_fee") }}' + + - name: trade_type + description: '{{ doc("trade_type") }}' + tests: + - not_null + + - name: rounding_slippage + description: '{{ doc("rounding_slippage") }}' + + - name: seller_is_exact + description: '{{ doc("seller_is_exact") }}' + + - name: fact_trades_id + description: '{{ doc("pk") }}' + tests: + - unique + - not_null + + - name: _inserted_timestamp + description: '{{ doc("inserted_timestamp") }}' + tests: + - not_null + + - name: inserted_timestamp + description: '{{ doc("inserted_timestamp") }}' + tests: + - not_null + + - name: modified_timestamp + description: '{{ doc("modified_timestamp") }}' + tests: + - not_null + + - name: _invocation_id + description: '{{ doc("invocation_id") }}' diff --git a/models/gold/core/fact__transactions.sql b/models/gold/core/fact__transactions.sql new file mode 100644 index 0000000..aa75e0e --- /dev/null +++ b/models/gold/core/fact__transactions.sql @@ -0,0 +1,74 @@ +-- depends_on: {{ ref('silver__transactions') }} +{{ config( + materialized = 'incremental', + unique_key = ["fact_transactions_id"], + incremental_predicates = ["dynamic_range_predicate", "partition_id::date"], + merge_exclude_columns = ["inserted_timestamp"], + cluster_by = ['closed_at::DATE','partition_id','modified_timestamp::DATE'], + tags = ['core'] +) }} + +SELECT + id as transaction_id, + transaction_hash, + ledger_sequence, + account, + account_sequence, + max_fee, + operation_count, + created_at, + memo_type, + memo, + time_bounds, + successful, + fee_charged, + inner_transaction_hash, + fee_account, + new_max_fee, + account_muxed, + fee_account_muxed, + batch_id, + batch_run_date, + batch_insert_ts, + ledger_bounds, + min_account_sequence, + min_account_sequence_age, + min_account_sequence_ledger_gap, + tx_envelope, + tx_result, + tx_meta, + tx_fee_meta, + extra_signers, + resource_fee, + soroban_resources_instructions, + soroban_resources_read_bytes, + soroban_resources_write_bytes, + closed_at, + transaction_result_code, + inclusion_fee_bid, + inclusion_fee_charged, + resource_fee_refund, + non_refundable_resource_fee_charged, + refundable_resource_fee_charged, + rent_fee_charged, + tx_signers, + refundable_fee, + _inserted_timestamp, + {{ dbt_utils.generate_surrogate_key( + ['id'] + ) }} AS fact_transactions_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM + {{ ref('silver__transactions') }} + +{% 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/fact__transactions.yml b/models/gold/core/fact__transactions.yml new file mode 100644 index 0000000..8bd9dfc --- /dev/null +++ b/models/gold/core/fact__transactions.yml @@ -0,0 +1,192 @@ +version: 2 + +models: + - name: fact__transactions + description: Fact table containing transaction details from the Stellar network. + columns: + - name: transactions_id + description: '{{ doc("pk") }}' + tests: + - unique + - not_null + + - name: id + description: Unique identifier for the transaction + tests: + - not_null + - unique + + - name: transaction_hash + description: '{{ doc("transaction_hash") }}' + tests: + - not_null + + - name: ledger_sequence + description: '{{ doc("ledger_sequence") }}' + tests: + - not_null + + - name: account + description: '{{ doc("account") }}' + tests: + - not_null + + - name: account_sequence + description: '{{ doc("account_sequence") }}' + tests: + - not_null + + - name: max_fee + description: '{{ doc("max_fee") }}' + tests: + - not_null + + - name: operation_count + description: '{{ doc("operation_count") }}' + tests: + - not_null + + - name: created_at + description: '{{ doc("txn_created_at") }}' + tests: + - not_null + + - name: memo_type + description: '{{ doc("memo_type") }}' + + - name: memo + description: '{{ doc("memo") }}' + + - name: time_bounds + description: '{{ doc("time_bounds") }}' + + - name: successful + description: '{{ doc("successful") }}' + tests: + - not_null + + - name: fee_charged + description: '{{ doc("fee_charged") }}' + tests: + - not_null + + - name: inner_transaction_hash + description: '{{ doc("inner_transaction_hash") }}' + + - name: fee_account + description: '{{ doc("fee_account") }}' + + - name: new_max_fee + description: '{{ doc("new_max_fee") }}' + + - name: account_muxed + description: '{{ doc("account_muxed") }}' + + - name: fee_account_muxed + description: '{{ doc("fee_account_muxed") }}' + + - name: batch_id + description: '{{ doc("batch_id") }}' + tests: + - not_null + + - name: batch_run_date + description: '{{ doc("batch_run_date") }}' + tests: + - not_null + + - name: batch_insert_ts + description: '{{ doc("batch_insert_ts") }}' + tests: + - not_null + + - name: ledger_bounds + description: '{{ doc("ledger_bounds") }}' + + - name: min_account_sequence + description: '{{ doc("min_account_sequence") }}' + + - name: min_account_sequence_age + description: '{{ doc("min_account_sequence_age") }}' + + - name: min_account_sequence_ledger_gap + description: '{{ doc("min_account_sequence_ledger_gap") }}' + + - name: tx_envelope + description: '{{ doc("tx_envelope") }}' + + - name: tx_result + description: '{{ doc("tx_result") }}' + + - name: tx_meta + description: '{{ doc("tx_meta") }}' + + - name: tx_fee_meta + description: '{{ doc("tx_fee_meta") }}' + + - name: extra_signers + description: '{{ doc("extra_signers") }}' + + - name: resource_fee + description: '{{ doc("resource_fee") }}' + + - name: soroban_resources_instructions + description: '{{ doc("soroban_resources_instructions") }}' + + - name: soroban_resources_read_bytes + description: '{{ doc("soroban_resources_read_bytes") }}' + + - name: soroban_resources_write_bytes + description: '{{ doc("soroban_resources_write_bytes") }}' + + - name: closed_at + description: '{{ doc("closed_at") }}' + tests: + - not_null + + - name: transaction_result_code + description: '{{ doc("transaction_result_code") }}' + + - name: inclusion_fee_bid + description: '{{ doc("inclusion_fee_bid") }}' + + - name: inclusion_fee_charged + description: '{{ doc("inclusion_fee_charged") }}' + + - name: resource_fee_refund + description: '{{ doc("resource_fee_refund") }}' + + - name: non_refundable_resource_fee_charged + description: '{{ doc("non_refundable_resource_fee_charged") }}' + + - name: refundable_resource_fee_charged + description: '{{ doc("refundable_resource_fee_charged") }}' + + - name: rent_fee_charged + description: '{{ doc("rent_fee_charged") }}' + + - name: tx_signers + description: '{{ doc("tx_signers") }}' + + - name: refundable_fee + description: '{{ doc("refundable_fee") }}' + + - name: _inserted_timestamp + description: '{{ doc("inserted_timestamp") }}' + tests: + - not_null + + - name: inserted_timestamp + description: '{{ doc("inserted_timestamp") }}' + tests: + - not_null + + - name: modified_timestamp + description: '{{ doc("modified_timestamp") }}' + tests: + - not_null + + - name: _invocation_id + description: '{{ doc("invocation_id") }}' + tests: + - not_null diff --git a/models/gold/operations/ez_operations.sql b/models/gold/operations/ez_operations.sql new file mode 100644 index 0000000..c90f973 --- /dev/null +++ b/models/gold/operations/ez_operations.sql @@ -0,0 +1,394 @@ +-- depends_on: {{ ref('fact__operations') }} +-- depends_on: {{ ref('fact__transactions') }} +-- depends_on: {{ ref('fact__ledgers') }} + +{{ config( + materialized="incremental", + unique_key=["op_id"], + cluster_by=["ledger_sequence","transaction_id","account","type"], + partition_by={"field": "closed_at","data_type": "timestamp","granularity": "month"}, + tags=["core"] +) }} + +WITH operations AS ( + SELECT + account_id as account, + op_account_muxed, + op_account_muxed_id, + op_account_id, + amount, + asset, + asset_code, + asset_issuer, + asset_type, + authorize, + coalesce(balance_id, claimable_balance_id) as balance_id, + claimant, + claimant_muxed, + claimant_muxed_id, + claimants, + data_account_id, + data_name, + buying_asset_code, + buying_asset_issuer, + buying_asset_type, + `from`, + from_muxed, + from_muxed_id, + funder, + funder_muxed, + funder_muxed_id, + high_threshold, + home_domain, + inflation_destination as inflation_dest, + `into`, + into_muxed, + into_muxed_id, + `limit`, + low_threshold, + master_key_weight, + med_threshold, + name, + offer_id, + path, + price, + price_r, + selling_asset_code, + selling_asset_issuer, + selling_asset_type, + set_flags, + set_flags_s, + signer_account_id, + signer_key, + signer_weight, + source_amount, + source_asset_code, + source_asset_issuer, + source_asset_type, + source_max, + starting_balance, + `to`, + to_muxed, + to_muxed_id, + trustee, + trustee_muxed, + trustee_muxed_id, + trustor, + trustor_muxed, + trustor_muxed_id, + trustline_account_id, + trustline_asset, + value, + clear_flags, + clear_flags_s, + destination_min, + bump_to, + sponsor, + sponsored_id, + begin_sponsor_id as begin_sponsor, + begin_sponsor_muxed, + begin_sponsor_muxed_id, + authorize_to_maintain_liability, + clawback_enabled, + liquidity_pool_id, + reserve_a_asset_type, + reserve_a_asset_code, + reserve_a_asset_issuer, + reserve_a_max_amount, + reserve_a_deposit_amount, + reserve_b_asset_type, + reserve_b_asset_code, + reserve_b_asset_issuer, + reserve_b_max_amount, + reserve_b_deposit_amount, + min_price, + min_price_r, + max_price, + max_price_r, + shares_received, + reserve_a_min_amount, + reserve_b_min_amount, + shares, + reserve_a_withdraw_amount, + reserve_b_withdraw_amount, + op_id, + op_source_account, + op_source_account_muxed, + transaction_id, + type, + type_string, + batch_id, + batch_run_date, + asset_balance_change, + parameters, + parameters_decoded, + function_name as function, + address, + soroban_operation_type, + extend_to, + contract_id, + contract_code_hash, + operation_result_code, + operation_trace_code, + details_json, + modified_timestamp, + _inserted_timestamp + FROM {{ ref('fact__operations') }} + {% if is_incremental() %} + WHERE modified_timestamp >= (SELECT MAX(modified_timestamp) FROM {{ this }}) + {% endif %} +), + +transactions AS ( + SELECT + transaction_id, + transaction_hash, + ledger_sequence, + txn_account, + account_sequence, + max_fee, + txn_operation_count, + txn_created_at, + memo_type, + memo, + time_bounds, + successful, + fee_charged, + fee_account, + new_max_fee, + account_muxed, + fee_account_muxed, + ledger_bounds, + min_account_sequence, + min_account_sequence_age, + min_account_sequence_ledger_gap, + extra_signers, + batch_id, + batch_run_date, + resource_fee, + soroban_resources_instructions, + soroban_resources_read_bytes, + soroban_resources_write_bytes, + transaction_result_code, + inclusion_fee_bid, + inclusion_fee_charged, + resource_fee_refund, + non_refundable_resource_fee_charged, + refundable_resource_fee_charged, + rent_fee_charged, + tx_signers, + refundable_fee + FROM {{ ref('fact__transactions') }} + {% if is_incremental() %} + WHERE modified_timestamp >= (SELECT MAX(modified_timestamp) FROM {{ this }}) + {% endif %} +), + +ledgers AS ( + SELECT + sequence, + ledger_hash, + previous_ledger_hash, + transaction_count, + operation_count as ledger_operation_count, + closed_at, + ledger_id, + total_coins, + fee_pool, + base_fee, + base_reserve, + max_tx_set_size, + protocol_version, + successful_transaction_count, + failed_transaction_count, + soroban_fee_write_1kb, + node_id, + signature, + total_byte_size_of_bucket_list, + batch_id, + batch_run_date + FROM {{ ref('fact__ledgers') }} + {% if is_incremental() %} + WHERE modified_timestamp >= (SELECT MAX(modified_timestamp) FROM {{ this }}) + {% endif %} +) + +SELECT + o.op_id, + o.op_source_account, + o.op_source_account_muxed, + o.transaction_id, + o.type, + o.type_string, + o.account, + o.op_account_muxed, + o.op_account_id, + o.op_account_muxed_id, + o.amount, + o.asset, + o.asset_code, + o.asset_issuer, + o.asset_type, + o.authorize, + o.balance_id, + o.claimant, + o.claimant_muxed, + o.claimant_muxed_id, + o.claimants, + o.data_account_id, + o.data_name, + o.buying_asset_code, + o.buying_asset_issuer, + o.buying_asset_type, + o.`from`, + o.from_muxed, + o.from_muxed_id, + o.funder, + o.funder_muxed, + o.funder_muxed_id, + o.high_threshold, + o.home_domain, + o.inflation_dest, + o.`into`, + o.into_muxed, + o.into_muxed_id, + o.`limit`, + o.low_threshold, + o.master_key_weight, + o.med_threshold, + o.name, + o.offer_id, + o.path, + o.price, + o.price_r.d, + o.price_r.n, + o.selling_asset_code, + o.selling_asset_issuer, + o.selling_asset_type, + o.set_flags, + o.set_flags_s, + o.signer_account_id, + o.signer_key, + o.signer_weight, + o.source_amount, + o.source_asset_code, + o.source_asset_issuer, + o.source_asset_type, + o.source_max, + o.starting_balance, + o.`to`, + o.to_muxed, + o.to_muxed_id, + o.trustee, + o.trustee_muxed, + o.trustee_muxed_id, + o.trustor, + o.trustor_muxed, + o.trustor_muxed_id, + o.trustline_account_id, + o.trustline_asset, + o.value, + o.clear_flags, + o.clear_flags_s, + o.destination_min, + o.bump_to, + o.sponsor, + o.sponsored_id, + o.begin_sponsor, + o.begin_sponsor_muxed, + o.begin_sponsor_muxed_id, + o.authorize_to_maintain_liability as authorize_to_maintain_liabilities, + o.clawback_enabled, + o.liquidity_pool_id, + o.reserve_a_asset_type, + o.reserve_a_asset_code, + o.reserve_a_asset_issuer, + o.reserve_a_max_amount, + o.reserve_a_deposit_amount, + o.reserve_b_asset_type, + o.reserve_b_asset_code, + o.reserve_b_asset_issuer, + o.reserve_b_max_amount, + o.reserve_b_deposit_amount, + o.min_price, + o.min_price_r, + o.max_price, + o.max_price_r, + o.shares_received, + o.reserve_a_min_amount, + o.reserve_b_min_amount, + o.shares, + o.reserve_a_withdraw_amount, + o.reserve_b_withdraw_amount, + o.asset_balance_change as asset_balance_changes, + o.parameters, + o.parameters_decoded, + o.function, + o.address, + o.soroban_operation_type, + o.extend_to, + o.contract_id, + o.contract_code_hash, + o.operation_result_code, + o.operation_trace_code, + t.transaction_hash, + t.ledger_sequence, + t.txn_account, + t.account_sequence, + t.max_fee, + t.txn_operation_count, + t.txn_created_at, + t.memo_type, + t.memo, + t.time_bounds, + t.successful, + t.fee_charged, + t.fee_account, + t.new_max_fee, + t.account_muxed, + t.fee_account_muxed, + t.ledger_bounds, + t.min_account_sequence, + t.min_account_sequence_age, + t.min_account_sequence_ledger_gap, + t.extra_signers, + t.resource_fee, + t.soroban_resources_instructions, + t.soroban_resources_read_bytes, + t.soroban_resources_write_bytes, + t.transaction_result_code, + t.inclusion_fee_bid, + t.inclusion_fee_charged, + t.resource_fee_refund, + l.ledger_hash, + l.previous_ledger_hash, + l.transaction_count, + l.ledger_operation_count, + l.closed_at, + l.ledger_id, + l.total_coins, + l.fee_pool, + l.base_fee, + l.base_reserve, + l.max_tx_set_size, + l.protocol_version, + l.successful_transaction_count, + l.failed_transaction_count, + l.soroban_fee_write_1kb, + l.node_id, + l.signature, + l.total_byte_size_of_bucket_list, + t.non_refundable_resource_fee_charged, + t.refundable_resource_fee_charged, + t.rent_fee_charged, + t.tx_signers, + t.refundable_fee, + '{{ dbt_utils.generate_surrogate_key(['op_id']) }}' AS fact_operations_id, + SYSDATE() AS inserted_timestamp, + SYSDATE() AS modified_timestamp, + '{{ invocation_id }}' AS _invocation_id +FROM operations o +LEFT JOIN transactions t + ON o.transaction_id = t.transaction_id +LEFT JOIN ledgers l + ON t.ledger_sequence = l.sequence diff --git a/models/gold/operations/ez_operations.yml b/models/gold/operations/ez_operations.yml new file mode 100644 index 0000000..5e102c4 --- /dev/null +++ b/models/gold/operations/ez_operations.yml @@ -0,0 +1,115 @@ +version: 2 + +models: + - name: ez_operations + description: A comprehensive view combining operations with their associated transaction and ledger data. + config: + tags: ["core"] + + columns: + - name: fact_operations_id + description: '{{ doc("pk") }}' + tests: + - unique + - not_null + + - name: op_id + description: '{{ doc("op_id") }}' + tests: + - not_null + + - name: transaction_id + description: '{{ doc("transaction_id") }}' + + - name: type + description: '{{ doc("type") }}' + + - name: account + description: '{{ doc("account") }}' + + - name: amount + description: '{{ doc("amount") }}' + + - name: asset_code + description: '{{ doc("asset_code") }}' + + - name: asset_issuer + description: '{{ doc("asset_issuer") }}' + + - name: asset_type + description: '{{ doc("asset_type") }}' + + - name: transaction_hash + description: '{{ doc("transaction_hash") }}' + + - name: ledger_sequence + description: '{{ doc("ledger_sequence") }}' + + - name: closed_at + description: '{{ doc("closed_at") }}' + + - name: successful + description: '{{ doc("successful") }}' + + - name: operation_result_code + description: '{{ doc("operation_result_code") }}' + + - name: operation_trace_code + description: '{{ doc("operation_trace_code") }}' + + - name: details_json + description: '{{ doc("details_json") }}' + + - name: asset_balance_changes + description: '{{ doc("asset_balance_changes") }}' + + - name: parameters + description: '{{ doc("parameters") }}' + + - name: parameters_decoded + description: '{{ doc("parameters_decoded") }}' + + - name: function + description: '{{ doc("function") }}' + + - name: contract_id + description: '{{ doc("contract_id") }}' + + - name: contract_code_hash + description: '{{ doc("contract_code_hash") }}' + + - name: resource_fee + description: '{{ doc("resource_fee") }}' + + - name: soroban_resources_instructions + description: '{{ doc("soroban_resources_instructions") }}' + + - name: soroban_resources_read_bytes + description: '{{ doc("soroban_resources_read_bytes") }}' + + - name: soroban_resources_write_bytes + description: '{{ doc("soroban_resources_write_bytes") }}' + + - name: non_refundable_resource_fee_charged + description: '{{ doc("non_refundable_resource_fee_charged") }}' + + - name: refundable_resource_fee_charged + description: '{{ doc("refundable_resource_fee_charged") }}' + + - name: rent_fee_charged + description: '{{ doc("rent_fee_charged") }}' + + - name: tx_signers + description: '{{ doc("tx_signers") }}' + + - name: refundable_fee + description: '{{ doc("refundable_fee") }}' + + - name: inserted_timestamp + description: '{{ doc("inserted_timestamp") }}' + + - name: modified_timestamp + description: '{{ doc("modified_timestamp") }}' + + - name: _invocation_id + description: '{{ doc("invocation_id") }}'