Skip to content

Commit

Permalink
fixing ton transactions and removing null test in stablecoins
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMelendez01 committed Nov 10, 2024
1 parent f00bc45 commit abdb893
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
models:
- name: agg_daily_stablecoin_breakdown_silver
tests:
- "dbt_expectations.expect_grouped_row_values_to_have_recent_data":
group_by: [CHAIN, SYMBOL]
timestamp_column: "DATE"
datepart: "day"
interval: 2
columns:
- name: "DATE"
tests:
Expand Down
1 change: 1 addition & 0 deletions models/staging/ton/__ton__sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ sources:
- name: raw_ton_app_daa
- name: raw_ton_app_txns_fees
- name: raw_ton_transactions
- name: raw_ton_transactions_avro
4 changes: 2 additions & 2 deletions models/staging/ton/fact_ton_fundamental_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ with flatten_ton_transaction as (
NOT ARRAY_CONTAINS(0, ARRAY_UNIQUE_AGG(success)) as success
, trace_id
, max(block_timestamp::date) as date
, min_by(transaction_account_interfaces, lt) as interfaces
, min_by(transaction_account_interface, lt) as interface
, min_by(transaction_account, lt) as first_account
, min_by(transaction_account_workchain, lt) as workchain
, sum(total_fees) as transaction_fees
Expand Down Expand Up @@ -37,7 +37,7 @@ dau as (
date
, count(distinct first_account) as dau
from flatten_ton_transaction
where success and GET(interfaces, 0) like 'wallet_v%'
where success and interface like '%wallet%'
group by date
)
SELECT
Expand Down
4 changes: 2 additions & 2 deletions models/staging/ton/fact_ton_rolling_active_addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with
flatten_ton_transactions as (
select
NOT ARRAY_CONTAINS(0, ARRAY_UNIQUE_AGG(success)) as success
, min_by(transaction_account_interfaces, lt) as interfaces
, min_by(transaction_account_interface, lt) as interface
, min_by(transaction_account, lt) as first_account
, max(block_timestamp::date) as raw_date
from {{ ref("fact_ton_transactions") }}
Expand All @@ -31,7 +31,7 @@ with
raw_date,
first_account as from_address
from flatten_ton_transactions
where success and GET(interfaces, 0) like 'wallet_v%'
where success and interface like '%wallet%'
),
rolling_mau as (
select
Expand Down
83 changes: 20 additions & 63 deletions models/staging/ton/fact_ton_transactions.sql
Original file line number Diff line number Diff line change
@@ -1,68 +1,25 @@
{{
config(
materialized="incremental",
unique_key="tx_id",
unique_key="tx_hash",
)
}}
with raw_data as (
select
extraction_date
, parse_json(source_json) as source_json
, parse_json(source_json):"decoded_hash"::string as tx_hash
, parse_json(source_json):"tx_id"::string as tx_id
, TO_TIMESTAMP(parse_json(source_json):"utime") as block_timestamp
, parse_json(source_json):"total_fees"::bigint as total_fees
, parse_json(source_json):"storage_ph_fees_collected"::bigint as storage_ph_fees_collected
, parse_json(source_json):"success"::boolean as success
, parse_json(source_json):"in_msg"::string as in_msg
, parse_json(source_json):"lt"::bigint as lt
, parse_json(source_json):"transaction_account"::string as transaction_account
, parse_json(source_json):"transaction_account_workchain"::int as transaction_account_workchain
, parse_json(source_json):"transaction_account_interfaces"::array as transaction_account_interfaces
, parse_json(source_json):"from_address"::string as from_address
, parse_json(source_json):"from_workchain"::int as from_workchain
, parse_json(source_json):"from_interfaces"::array as from_interfaces
, parse_json(source_json):"to_address"::string as to_address
, parse_json(source_json):"to_workchain"::int as to_workchain
, parse_json(source_json):"to_interfaces"::array as to_interfaces
, parse_json(source_json):"trace_id"::string as trace_id
, parse_json(source_json):"op_code"::string as op_code
, parse_json(parse_json(source_json):"decoded_body") as decoded_body
, parse_json(source_json):"init"::string as init
, parse_json(source_json):"value"::bigint as value
, parse_json(source_json):"msg_type"::string as msg_type
, parse_json(source_json):"init_interfaces"::array as init_interfaces
from
{{ source("PROD_LANDING", "raw_ton_transactions") }}
{% if is_incremental() %}
where TO_TIMESTAMP(parse_json(source_json):"utime") > (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
and extraction_date > (select dateadd('day', -3, max(block_timestamp)) from {{ this }})
{% endif %}
)
select
max_by(tx_hash, extraction_date) as tx_hash
, tx_id
, max_by(block_timestamp, extraction_date) as block_timestamp
, max_by(total_fees, extraction_date) as total_fees
, max_by(storage_ph_fees_collected, extraction_date) as storage_ph_fees_collected
, max_by(success, extraction_date) as success
, max_by(in_msg, extraction_date) as in_msg
, max_by(lt, extraction_date) as lt
, max_by(transaction_account, extraction_date) as transaction_account
, max_by(transaction_account_workchain, extraction_date) as transaction_account_workchain
, max_by(transaction_account_interfaces, extraction_date) as transaction_account_interfaces
, max_by(from_address, extraction_date) as from_address
, max_by(from_workchain, extraction_date) as from_workchain
, max_by(from_interfaces, extraction_date) as from_interfaces
, max_by(to_address, extraction_date) as to_address
, max_by(to_workchain, extraction_date) as to_workchain
, max_by(to_interfaces, extraction_date) as to_interfaces
, max_by(trace_id, extraction_date) as trace_id
, max_by(op_code, extraction_date) as op_code
, max_by(decoded_body, extraction_date) as decoded_body
, max_by(init, extraction_date) as init
, max_by(value, extraction_date) as value
, max_by(msg_type, extraction_date) as msg_type
, max_by(init_interfaces, extraction_date) as init_interfaces
from raw_data
group by tx_id
select
avro_raw:hash::string as tx_hash
, avro_raw:trace_id::string as trace_id
, avro_raw:now::timestamp as block_timestamp
, block_timestamp::date as raw_date
, avro_raw:total_fees::float as total_fees
, avro_raw:storage_fees_collected::float as storage_ph_fees_collected
, avro_raw:lt::bigint as lt
, avro_raw:account::string as transaction_account
, avro_raw:block_workchain::number as transaction_account_workchain
, avro_raw:account_state_code_hash_after::string as account_code_hash
, interface as transaction_account_interface
, not avro_raw:aborted::boolean as success
from {{ source("PROD_LANDING", "raw_ton_transactions_avro") }}
left join {{ref("ton_tagged_interfaces")}} on account_code_hash = code_hash
where avro_raw:now::timestamp::date >= '2022-06-28'
{% if is_incremental() %}
and avro_raw:now::timestamp > (select dateadd('day', -5, max(block_timestamp)) from {{ this }})
{% endif %}
38 changes: 38 additions & 0 deletions seeds/ton_tagged_interfaces.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interface,code_hash
wallet_v2r1,XJpeaMEI4YchoHxC+ZVr+zmtd+xtYktgxXbsiO7mUyk=
wallet_v3r1,thBBpYp5gLlG6PueGY48kE0keZ/6NldOpCUcQaVm9YE=
wallet_v3r2,hNr6RJ+Ypph3ibojI1gHK8D3bcRSQAKl0JGLmnXS1Zk=
wallet_v4r2,/rX/aCDi/w2Ug+fg1iyBfYRniftK5YDIeIZtlZ2r1cA=
wallet_v5r1,IINLe3KxEhR+Gy+0V7hOdNGjDwT3N9T2KmaOlVLSty8=
wallet_v2r2,/pUw0yQ4Uwg+8u8LTCkIwKv2+hwx6iQ6rKpb+MfXU/E=
jetton_wallet,St9IE1y1da267Udnmch/8pBCabH5Sa2k0EeekQS28hc=
jetton_wallet,jSjqQht36AX+pSrPM1KWSZ8Drsjp/SHdtfJWSqZcSN4=
jetton_wallet,vrBoPr64kn/p/I7AoYvH3ReJlomCWhIeq0bFo6hg0M4=
jetton_wallet,p2DWKdU0PnbQRQF9ncIW/IoweoN3gV/rKwpcSQ5zNIY=
jetton_wallet,iUaPAseOVwgC45l5yFFvw43wfqdqSDV+BTbyuns+43s=
highload_wallet,EayteVWEQJDyg78ji8FEmHH3g+fMCXlAjT9IWUg+hSU=
highload_wallet,ID3U81ittJmTEpqpJcrDmRa2ig5PeNJujywraer6Vnk=
telegram_username,p6Jhak1jmgdsL2fnzOBCP9Khwu5VCtZRwe2hbuE7yso=
jetton_wallet,ngbKMOUIptn7IRZ8u49mOZ7dEZCwsB4LvRTFRsyXpys=
jetton_wallet,G70kKn2Quq4lGKFrmkk04QN8WlrhTAChzLhn7bTpkAA=
jetton_wallet,D2JLuV8P4sEBYC17ZjTt0fnbCVTb5WLZX7pK5SOki6k=
jetton_wallet,wSJ1CF7H3SGSXDOpGWgBhgIsbypM7UXbzj0+FNQ43A8=
jetton_wallet,St9IE1y1da267Udnmch/8pBCabH5Sa2k0EeekQS28hc=
wallet,89fKU0k97trCizgZhqhJQDy6w9LFhHea8IEGWvCsS5M=
jetton_wallet,Er67DcjiArfib3IeJUfha7nrrsk09lfRnyLnbWK+yHg=
jetton_wallet,c9JVo8HZ+BVm3NxZjuTVqhN8LF2ADzD3bfFFeEbIXQA=
jetton_wallet,eqG3vmgENk7aC/453lGY0t2R9O7/XrVy7gSz6mqogdk=
jetton_wallet,tG2DiAEYF4vdmUiAyF5UQVtEni8yug+PoU15imCmMNg=
jetton_wallet,5jBjBgkm5u8sbRf/rn9f4pqRZ4AgxBnRZ+Df82OOJ2E=
jetton_wallet,Wg7v0SLD2hOkEB9gZ32sppO2Y6joIedI87YCct8GBAk=
jetton_wallet,7HwwkZHKs3Fk+v3NhxmFqteqasQpw8snWA4TRdHLuNs=
jetton_wallet,GTICC4gjzXYW+2ndcwvmD4vJoJFHbIKfCK2Zt8bBmGk=
jetton_wallet,EoYOttdrVtxt6hcx00HyF1r4OXcp2cgBCbRCtvVfxNA=
jetton_wallet,AYxwUCaWGz3so8d0jrhqWSOHtTewSk00ZaFr6mWuV3g=
jetton_wallet,LXly9xL8OYvDL2eWmArXEZB0NKMRtX/nLSD3UQshI+Y=
jetton_wallet,SNsWmBMNTmFwWwkFYnfTm+ua6CwCnqCw8oWM9wERGDo=
jetton_wallet,sGeU5cSwMCag8821Arie1lms+Dw8qCLg3LMWIBSKZRc=
jetton_wallet,g/i91QcNfvUmJL/nLF9U9rYn1vIczLDi/NltNKyKwRU=
jetton_wallet,EZtQX38sFSfHK3o4D5blXHyo6dyO7rAJ9cgJozIOUmQ=
jetton_wallet,H80Uq+vJFFcfwZRSBQg82w29wQLUkdu8qisgG/VLOJE=
jetton_wallet,sDEAOv+t+YnUPDwKNZDZxFnFg/B02WqUeINDWM4mJwg=

0 comments on commit abdb893

Please sign in to comment.