Skip to content

Commit

Permalink
Merge pull request #52 from Artemis-xyz/son/fix-sui-duplication-error
Browse files Browse the repository at this point in the history
Fixed Duplicates Error
  • Loading branch information
Sunny77D authored May 6, 2024
2 parents e8ba3b1 + 6ea3e5b commit 7ab6e69
Showing 1 changed file with 53 additions and 32 deletions.
85 changes: 53 additions & 32 deletions models/staging/sui/fact_sui_transactions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,60 @@ sui_transactions as (
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
and block_time
>= (select dateadd('day', -5, max(block_timestamp)) from {{ this }})
>= (select dateadd('day', -7, max(block_timestamp)) from {{ this }})
{% endif %}
group by transaction_block_digest
),
prices as ({{ get_coingecko_price_with_latest("sui") }})
prices as ({{ get_coingecko_price_with_latest("sui") }}),
transactions_cte as (
select
digest as tx_hash,
tb.block_time as block_timestamp,
date_trunc('day', tb.block_time) as raw_date,
sender,
(total_gas_cost + storage_rebate - storage_cost)/10e8 as tx_fee,
(non_refundable_storage_fee + storage_cost - storage_rebate)/10e8 as native_revenue,
(total_gas_cost + storage_rebate - storage_cost)/10e8 * price as gas_usd,
(non_refundable_storage_fee + storage_cost - storage_rebate)/10e8 * price as revenue,
package,
new_contracts.name,
new_contracts.app,
new_contracts.friendly_name,
new_contracts.sub_category,
case
when package is null and array_size(type_array) = 2 and ARRAY_CONTAINS('TransferObjects'::variant, type_array)
then 'EOA'
else new_contracts.category
end as category,
'sui' as chain,
status
from {{ source('ZETTABLOCKS_SUI', 'transaction_blocks') }} as tb
left join sui_transactions as t on lower(digest) = lower(transaction_block_digest)
left join new_contracts on lower(package) = lower(address)
left join prices on raw_date = prices.date
where raw_date < to_date(sysdate())
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
and block_timestamp
>= (select dateadd('day', -7, max(block_timestamp)) from {{ this }})
{% endif %}
)
select
digest as tx_hash,
tb.block_time as block_timestamp,
date_trunc('day', tb.block_time) as raw_date,
sender,
(total_gas_cost + storage_rebate - storage_cost)/10e8 as tx_fee,
(non_refundable_storage_fee + storage_cost - storage_rebate)/10e8 as native_revenue,
(total_gas_cost + storage_rebate - storage_cost)/10e8 * price as gas_usd,
(non_refundable_storage_fee + storage_cost - storage_rebate)/10e8 * price as revenue,
package,
new_contracts.name,
new_contracts.app,
new_contracts.friendly_name,
new_contracts.sub_category,
case
when package is null and array_size(type_array) = 2 and ARRAY_CONTAINS('TransferObjects'::variant, type_array)
then 'EOA'
else new_contracts.category
end as category,
'sui' as chain,
status
from {{ source('ZETTABLOCKS_SUI', 'transaction_blocks') }} as tb
left join sui_transactions as t on lower(digest) = lower(transaction_block_digest)
left join new_contracts on lower(package) = lower(address)
left join prices on raw_date = prices.date
where raw_date < to_date(sysdate())
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
and block_timestamp
>= (select dateadd('day', -5, max(block_timestamp)) from {{ this }})
{% endif %}
tx_hash,
max(block_timestamp) as block_timestamp,
max(raw_date) as raw_date,
max(sender) as sender,
max(tx_fee) as tx_fee,
max(native_revenue) as native_revenue,
max(gas_usd) as gas_usd,
max(revenue) as revenue,
max(package) as package,
max(name) as name,
max(app) as app,
max(friendly_name) as friendly_name,
max(sub_category) as sub_category,
max(category) as category,
max(chain) as chain,
max(status) as status
from transactions_cte
group by tx_hash

0 comments on commit 7ab6e69

Please sign in to comment.