Skip to content

Commit

Permalink
Merge pull request #53 from Artemis-xyz/sm-near-p2p_models
Browse files Browse the repository at this point in the history
P2P Volumes: Adding near models
  • Loading branch information
SebMelendez01 authored May 6, 2024
2 parents 7ab6e69 + 4a9b124 commit f9953fc
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 4 deletions.
9 changes: 7 additions & 2 deletions macros/p2p/filter_p2p_token_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@
dex_swap_liquidity as (
select
sum(amount_in_usd) as daily_volume,
token_in,
token_out
{% if chain == "near" %}
token_in_contract as token_in,
token_out_contract as token_out
{% else %}
token_in,
token_out
{% endif %}
from {{ chain }}_flipside.defi.ez_dex_swaps
where amount_in_usd is not null and amount_out_usd is not null and
abs(
Expand Down
15 changes: 15 additions & 0 deletions macros/p2p/p2p_native_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
prices as ({{ get_coingecko_price_with_latest("tron") }}),
{% elif chain == "solana" %}
prices as ({{ get_coingecko_price_with_latest("solana") }}),
{% elif chain == "near" %}
prices as ({{ get_coingecko_price_with_latest("near") }}),
{% else %}
prices as ({{ get_coingecko_price_with_latest("ethereum") }}),
{% endif %}
Expand Down Expand Up @@ -46,6 +48,19 @@
and t1.tx_from != t1.tx_to
and lower(t1.tx_from) != lower('1nc1nerator11111111111111111111111111111111') -- Burn address of solana
and lower(t1.tx_to) != lower('1nc1nerator11111111111111111111111111111111')
{% elif chain == "near" %}
select
block_timestamp,
block_id as block_number,
tx_hash,
fact_token_transfers_id as index,
from_address,
to_address,
amount_raw_precise as raw_amount_precise,
amount_raw_precise / 1E24 as amount_precise
from near_flipside.core.ez_token_transfers
where from_address != to_address and transfer_type = 'native'
and from_address is not null and to_address is not null
{% else %}
select
block_timestamp,
Expand Down
25 changes: 25 additions & 0 deletions macros/p2p/p2p_token_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@
and t1.tx_from != t1.tx_to
and lower(t1.tx_from) != lower('1nc1nerator11111111111111111111111111111111') -- Burn address of solana
and lower(t1.tx_to) != lower('1nc1nerator11111111111111111111111111111111')
{% elif chain == "near" %}
select
block_timestamp,
block_id as block_number,
tx_hash,
fact_token_transfers_id as index,
from_address,
to_address,
amount_raw_precise as raw_amount_precise,
coalesce(amount_raw_precise/pow(10, decimals), 0) as amount_precise,
t1.contract_address as token_address,
coalesce((amount_raw_precise/pow(10, decimals)) * price, 0) as amount_usd
from near_flipside.core.ez_token_transfers t1
inner join near_flipside.core.dim_ft_contract_metadata t2 on t1.contract_address = t2.contract_address
inner join (
select
timestamp::date as date,
token_contract,
avg(price_usd) as price
from near_flipside.price.fact_prices
group by 1, 2
) t3 on t3.token_contract = t1.contract_address and block_timestamp::date = t3.date
where from_address != to_address and transfer_type = 'nep141'
and from_address is not null and to_address is not null
and from_address <> 'system' and to_address <> 'system'
{% else %}
select
block_timestamp,
Expand Down
5 changes: 5 additions & 0 deletions macros/wallets/distinct_eoa_addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
{% elif chain == "solana" %}
select distinct signer as address, 'signer' as address_type
from solana_flipside.core.ez_signers
{% elif chain == "near" %}
select distinct tx_signer as address, 'signer' as address_type
from near_flipside.core.fact_transactions
--tx_singer is a contract: https://flipsidecrypto.github.io/near-models/#!/model/model.near.core__fact_actions_events_function_call
where tx_signer not in (select receiver_id from near_flipside.core.fact_actions_events_function_call where method_name is not null)
{% else %}
select
distinct from_address as address, 'eoa' as address_type
Expand Down
1 change: 1 addition & 0 deletions models/dimensions/wallet/dim_near_eoa_addresses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ distinct_eoa_addresses("near") }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ config(materialized="table") }}
select symbol, contract_address, num_decimals, coingecko_id, initial_supply
from
(
values
('USDC', '17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1', 6, 'usd-coin', 0),
('USDT', 'usdt.tether-token.near', 6, 'tether', 0)
) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply)
10 changes: 8 additions & 2 deletions models/projects/near/core/ez_near_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ with
select date, revenue_native, revenue from {{ ref("fact_near_revenue_gold") }}
),
github_data as ({{ get_github_metrics("near") }}),
contract_data as ({{ get_contract_metrics("near") }})
contract_data as ({{ get_contract_metrics("near") }}),
p2p_metrics as ({{ get_p2p_metrics("near") }})

select
fundamental_data.date,
Expand All @@ -43,11 +44,16 @@ select
weekly_developers_core_ecosystem,
weekly_developers_sub_ecosystem,
weekly_contracts_deployed,
weekly_contract_deployers
weekly_contract_deployers,
p2p_native_transfer_volume,
p2p_token_transfer_volume,
p2p_stablecoin_transfer_volume,
p2p_transfer_volume
from fundamental_data
left join price_data on fundamental_data.date = price_data.date
left join defillama_data on fundamental_data.date = defillama_data.date
left join revenue_data on fundamental_data.date = revenue_data.date
left join github_data on fundamental_data.date = github_data.date
left join contract_data on fundamental_data.date = contract_data.date
left join p2p_metrics on fundamental_data.date = p2p_metrics.date
where fundamental_data.date < to_date(sysdate())
45 changes: 45 additions & 0 deletions models/staging/near/_test_fact_near_p2p_transfer_volume.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
models:
- name: fact_near_p2p_transfer_volume
tests:
- "dbt_expectations.expect_table_row_count_to_be_between:":
min_value: 1
max_value: 1000000
columns:
- name: CHAIN
tests:
- not_null
- dbt_expectations.expect_column_to_exist
- name: p2p_native_transfer_volume
tests:
- not_null
- dbt_expectations.expect_column_to_exist
- dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs:
date_column_name: DATE
period: day
lookback_periods: 1
trend_periods: 14
test_periods: 28
sigma_threshold: 3
take_logs: true
severity: warn
- name: p2p_transfer_volume
tests:
- not_null
- dbt_expectations.expect_column_to_exist
- dbt_expectations.expect_column_values_to_be_within_n_moving_stdevs:
date_column_name: DATE
period: day
lookback_periods: 1
trend_periods: 14
test_periods: 28
sigma_threshold: 3
take_logs: true
severity: warn
- name: DATE
tests:
- not_null
- dbt_expectations.expect_column_to_exist
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: day
interval: 3
severity: warn
9 changes: 9 additions & 0 deletions models/staging/near/fact_near_p2p_native_transfers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{
config(
materialized="incremental",
unique_key=["tx_hash", "index"],
snowflake_warehouse="NEAR",
)
}}

{{ p2p_native_transfers("near") }}
8 changes: 8 additions & 0 deletions models/staging/near/fact_near_p2p_token_transfers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{
config(
materialized="table",
snowflake_warehouse="NEAR",
)
}}

{{ filter_p2p_token_transfers("near", 1000)}}
9 changes: 9 additions & 0 deletions models/staging/near/fact_near_p2p_token_transfers_silver.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{
config(
materialized="incremental",
unique_key=["tx_hash", "index"],
snowflake_warehouse="NEAR",
)
}}

{{ p2p_token_transfers("near") }}
8 changes: 8 additions & 0 deletions models/staging/near/fact_near_p2p_transfer_volume.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{
config(
materialized="table",
snowflake_warehouse="NEAR",
)
}}

{{ p2p_transfer_volume("near") }}

0 comments on commit f9953fc

Please sign in to comment.