-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into blast-asset
- Loading branch information
Showing
71 changed files
with
1,746 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ ETHEREUM_FLIPSIDE | |
FLOW_FLIPSIDE | ||
GEODNET | ||
GNOSIS_FLIPSIDE | ||
HELIUM | ||
INJECTIVE | ||
LANDING_DATABASE | ||
NEAR | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- This model currently does not take into account native tokens. | ||
-- We do not have access to traces from quicknode yet. | ||
-- Only use ("celo") address balances for stablecoin data | ||
{% macro address_credits_quicknode(chain) %} | ||
select | ||
to_address as address, | ||
contract_address, | ||
block_timestamp, | ||
cast(amount as float) as credit, | ||
null as credit_usd, | ||
transaction_hash as tx_hash, | ||
null as trace_index, | ||
event_index | ||
from {{ ref("fact_" ~ chain ~ "_token_transfers") }} | ||
where | ||
to_address <> lower('0x0000000000000000000000000000000000000000') | ||
and to_date(block_timestamp) < to_date(sysdate()) | ||
{% if is_incremental() %} | ||
and block_timestamp | ||
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) | ||
{% endif %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- This model currently does not take into account native tokens. | ||
-- We do not have access to traces from quicknode yet. | ||
-- Only use ("celo") address balances for stablecoin data | ||
{% macro address_debits_quicknode(chain) %} | ||
select | ||
from_address as address, | ||
contract_address, | ||
block_timestamp, | ||
cast(amount * -1 as float) as debit, | ||
null as debit_usd, | ||
transaction_hash as tx_hash, | ||
null as trace_index, | ||
event_index | ||
from {{ ref("fact_" ~ chain ~ "_token_transfers")}} | ||
where | ||
to_date(block_timestamp) < to_date(sysdate()) | ||
and from_address <> lower('0x0000000000000000000000000000000000000000') | ||
{% if is_incremental() %} | ||
and block_timestamp | ||
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) | ||
{% endif %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% macro token_transfer_events(chain) %} | ||
select | ||
block_timestamp, | ||
block_number, | ||
transaction_hash, | ||
event_index, | ||
origin_from_address, | ||
origin_to_address, | ||
contract_address, | ||
decoded_log:"from"::string as from_address, | ||
decoded_log:"to"::string as to_address, | ||
try_to_number(decoded_log:"value"::string) as amount, | ||
tx_status | ||
from {{ ref("fact_" ~ chain ~ "_decoded_events") }} | ||
where topic_zero = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' | ||
and data != '0x' | ||
and amount is not null | ||
and tx_status = 1 | ||
{% if is_incremental() %} | ||
and | ||
block_timestamp | ||
>= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) | ||
{% endif %} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{% macro get_cohort_retention(chain) %} | ||
with | ||
min_date as ( | ||
select | ||
date_trunc('month', min(raw_date)) as first_month | ||
from {{ ref( "ez_" ~ chain ~ "_transactions") }} | ||
), | ||
base_table as( | ||
select | ||
date_trunc('month', raw_date) as base_month, | ||
from_address as address | ||
from {{ ref( "ez_" ~ chain ~ "_transactions") }} | ||
group by 1,2 | ||
), | ||
-- from user_cohorts onward, should be able to reuse ctes on any chain | ||
|
||
-- grab each users first action timestamp on chain | ||
user_cohorts as ( | ||
select | ||
address, | ||
min(base_month) as cohort_month | ||
from | ||
base_table | ||
group by 1 | ||
), | ||
|
||
--compute cohort size per distinct cohort period | ||
cohort_size as ( | ||
select | ||
cohort_month, | ||
count(distinct(address)) as cohort_size | ||
from | ||
user_cohorts | ||
group by 1 | ||
), | ||
|
||
-- determine if/ when users came back for another interaction based on period number | ||
following_months as ( | ||
select | ||
bt.address, | ||
timestampdiff(month, uc.cohort_month, bt.base_month) as month_number | ||
from | ||
base_table as bt | ||
inner join user_cohorts as uc on bt.address = uc.address | ||
where | ||
bt.base_month > uc.cohort_month | ||
group by | ||
bt.address, | ||
month_number | ||
), | ||
--aggregate and calcualte the retained user amount per time period per cohort | ||
retention_data as( | ||
select | ||
uc.cohort_month as cohort_month, | ||
fm.month_number, | ||
count(distinct(fm.address)) as retained_user_count | ||
from | ||
following_months as fm | ||
inner join user_cohorts as uc on fm.address = uc.address | ||
where | ||
cohort_month >= (select first_month from min_date) -- Grab data from the beginning of the month 24 months ago | ||
group by | ||
uc.cohort_month, | ||
fm.month_number | ||
) | ||
select | ||
'{{ chain }}' as chain, | ||
r.cohort_month, | ||
c.cohort_size, | ||
r.month_number, | ||
round(r.retained_user_count::numeric / c.cohort_size::numeric , 2) as retention_ratio | ||
from | ||
retention_data as r | ||
inner join cohort_size as c on r.cohort_month = c.cohort_month | ||
order by | ||
r.cohort_month, | ||
r.month_number | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ where | |
) | ||
and category is not null | ||
and app is null | ||
and gas is not null | ||
and txns is not null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{{ config(materialized="table", snowflake_warehouse="RETENTION") }} | ||
|
||
with retention_data as ( | ||
{{ | ||
dbt_utils.union_relations( | ||
relations=[ | ||
ref("ez_arbitrum_retention"), | ||
ref("ez_avalanche_retention"), | ||
ref("ez_base_retention"), | ||
ref("ez_bsc_retention"), | ||
ref("ez_ethereum_retention"), | ||
ref("ez_near_retention"), | ||
ref("ez_optimism_retention"), | ||
ref("ez_polygon_retention"), | ||
ref("ez_tron_retention") | ||
], | ||
) | ||
}} | ||
) | ||
SELECT | ||
concat( | ||
coalesce(cast(chain as string), '_this_is_null_'), | ||
'|', | ||
coalesce(cast(cohort_month as string), '_this_is_null_'), | ||
'|', | ||
coalesce(cast(month_number as string), '_this_is_null_') | ||
) as unique_id, | ||
chain, | ||
cohort_month, | ||
cohort_size, | ||
month_number, | ||
retention_ratio | ||
FROM retention_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.