-
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.
- Loading branch information
Showing
54 changed files
with
2,559 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro hex_string_to_evm_address(hex_string) %} | ||
PC_DBT_DB.PROD.HEX_STRING_TO_EVM_ADDRESS({{ hex_string }}) | ||
{% 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,3 @@ | ||
{% macro base58_to_hex(base58_string) %} | ||
PC_DBT_DB.PROD.BASE58_TO_HEX({{ base58_string }}) | ||
{% 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,3 @@ | ||
{% macro big_endian_hex_to_decimal(hex_string) %} | ||
PC_DBT_DB.PROD.BIG_ENDIAN_HEX_TO_DECIMAL({{ hex_string }}) | ||
{% 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,3 @@ | ||
{% macro hex_to_base58(hex_string) %} | ||
PC_DBT_DB.PROD.HEX_TO_BASE58({{ hex_string }}) | ||
{% 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,109 @@ | ||
|
||
{{ | ||
config( | ||
materialized='table', | ||
snowflake_warehouse='MAPLE', | ||
database='MAPLE', | ||
schema='core', | ||
alias='ez_metrics' | ||
) | ||
}} | ||
|
||
|
||
|
||
with fees as ( | ||
SELECT | ||
date, | ||
SUM(net_interest_usd) AS fees, | ||
SUM(net_interest_usd) AS supply_side_fees, | ||
SUM(platform_fees_usd) AS platform_fees, | ||
SUM(delegate_fees_usd) AS delegate_fees | ||
FROM {{ ref('fact_maple_fees') }} | ||
GROUP BY 1 | ||
) | ||
, revenues as ( | ||
SELECT | ||
date, | ||
SUM(revenue) AS revenue | ||
FROM {{ ref('fact_maple_revenue') }} | ||
GROUP BY 1 | ||
) | ||
, token_incentives as ( | ||
SELECT | ||
DATE(block_timestamp) AS date, | ||
SUM(incentive_usd) AS token_incentives | ||
FROM {{ ref('fact_maple_token_incentives') }} | ||
GROUP BY 1 | ||
) | ||
, tvl as ( | ||
SELECT | ||
date, | ||
SUM(tvl) AS tvl, | ||
SUM(outstanding_supply) AS outstanding_supply | ||
FROM {{ ref('fact_maple_agg_tvl') }} | ||
GROUP BY 1 | ||
) | ||
, treasury as ( | ||
SELECT | ||
date, | ||
SUM(usd_balance) AS treasury_value | ||
FROM {{ ref('fact_maple_treasury') }} | ||
GROUP BY 1 | ||
) | ||
, net_treasury as ( | ||
SELECT | ||
date, | ||
SUM(usd_balance) AS net_treasury_value | ||
FROM {{ ref('fact_maple_treasury') }} | ||
WHERE token <> 'MPL' | ||
GROUP BY 1 | ||
) | ||
, treasury_native as ( | ||
SELECT | ||
date, | ||
SUM(native_balance) AS treasury_value_native | ||
FROM {{ ref('fact_maple_treasury') }} | ||
WHERE token = 'MPL' | ||
GROUP BY 1 | ||
) | ||
, price as( | ||
{{ get_coingecko_metrics('maple')}} | ||
) | ||
, tokenholders as ( | ||
SELECT * FROM {{ ref('fact_maple_tokenholder_count')}} | ||
) | ||
|
||
SELECT | ||
price.date, | ||
coalesce(fees.fees, 0) as interest_fees, | ||
coalesce(fees.platform_fees, 0) as platform_fees, | ||
coalesce(fees.delegate_fees, 0) as delegate_fees, | ||
coalesce(fees.fees, 0) as fees, | ||
coalesce(interest_fees, 0) - coalesce(platform_fees, 0) - coalesce(delegate_fees, 0) as primary_supply_side_revenue, | ||
coalesce(primary_supply_side_revenue, 0) as total_supply_side_revenue, | ||
coalesce(revenues.revenue, 0) as revenue, | ||
coalesce(token_incentives.token_incentives, 0) as token_incentives, | ||
coalesce(token_incentives.token_incentives, 0) as total_expenses, | ||
coalesce(revenue, 0) - coalesce(total_expenses, 0) as protocol_earnings, | ||
coalesce(treasury.treasury_value, 0) as treasury_value, | ||
coalesce(treasury_native.treasury_value_native, 0) as treasury_value_native, | ||
coalesce(net_treasury.net_treasury_value, 0) as net_treasury_value, | ||
coalesce(tvl.tvl, 0) as tvl, | ||
coalesce(tvl.tvl, 0) as net_deposits, | ||
coalesce(tvl.outstanding_supply, 0) as outstanding_supply, | ||
coalesce(price.price, 0) as price, | ||
coalesce(price.market_cap, 0) as market_cap, | ||
coalesce(price.fdmc, 0) as fdmc, | ||
price.token_turnover_circulating, | ||
price.token_turnover_fdv, | ||
price.token_volume, | ||
tokenholders.token_holder_count | ||
FROM price | ||
LEFT JOIN fees USING(date) | ||
LEFT JOIN revenues USING(date) | ||
LEFT JOIN token_incentives USING(date) | ||
LEFT JOIN tvl USING(date) | ||
LEFT JOIN treasury USING(date) | ||
LEFT JOIN treasury_native USING(date) | ||
LEFT JOIN net_treasury USING(date) | ||
LEFT JOIN tokenholders USING(date) |
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,34 @@ | ||
{{ | ||
config( | ||
materialized = 'view', | ||
snowflake_warehouse = 'MAPLE', | ||
database = 'MAPLE', | ||
schema = 'core', | ||
alias = 'ez_metrics_by_chain' | ||
) | ||
}} | ||
|
||
SELECT | ||
date, | ||
'ethereum' as chain, | ||
interest_fees, | ||
primary_supply_side_revenue, | ||
total_supply_side_revenue, | ||
revenue, | ||
token_incentives, | ||
total_expenses, | ||
protocol_earnings, | ||
treasury_value, | ||
treasury_value_native, | ||
net_treasury_value, | ||
tvl, | ||
net_deposits, | ||
outstanding_supply, | ||
price, | ||
market_cap, | ||
fdmc, | ||
token_turnover_circulating, | ||
token_turnover_fdv, | ||
token_volume, | ||
token_holder_count | ||
FROM {{ ref('ez_maple_metrics') }} |
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,40 @@ | ||
{{ | ||
config( | ||
materialized='table', | ||
snowflake_warehouse='MAPLE', | ||
database='MAPLE', | ||
schema='core', | ||
alias='ez_metrics_by_pool' | ||
) | ||
}} | ||
|
||
with fees as ( | ||
SELECT | ||
date, | ||
pool_name, | ||
SUM(net_interest_usd) AS fees, | ||
SUM(platform_fees_usd) AS platform_fees, | ||
SUM(delegate_fees_usd) AS delegate_fees | ||
FROM {{ ref('fact_maple_fees') }} | ||
GROUP BY 1, 2 | ||
) | ||
, tvl as ( | ||
SELECT | ||
date, | ||
pool_name, | ||
SUM(tvl_native) AS tvl_native, | ||
SUM(tvl) AS tvl, | ||
SUM(outstanding_supply) AS outstanding_supply | ||
FROM {{ ref('fact_maple_agg_tvl') }} | ||
GROUP BY 1, 2 | ||
) | ||
SELECT | ||
coalesce(fees.date, tvl.date) as date, | ||
coalesce(fees.pool_name, tvl.pool_name) as pool_name, | ||
fees.fees, | ||
fees.platform_fees, | ||
fees.delegate_fees, | ||
tvl.tvl, | ||
tvl.outstanding_supply | ||
FROM fees | ||
FULL OUTER JOIN tvl ON fees.date = tvl.date AND fees.pool_name = tvl.pool_name |
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,98 @@ | ||
|
||
{{ | ||
config( | ||
materialized='table', | ||
snowflake_warehouse='MAPLE', | ||
database='MAPLE', | ||
schema='core', | ||
alias='ez_metrics_by_token' | ||
) | ||
}} | ||
|
||
with fees as ( | ||
SELECT | ||
date, | ||
asset as token, | ||
SUM(net_interest_native) AS fees_native, | ||
SUM(platform_fees_native) AS platform_fees_native, | ||
SUM(delegate_fees_native) AS delegate_fees_native | ||
FROM {{ ref('fact_maple_fees') }} | ||
GROUP BY 1, 2 | ||
) | ||
, revenues as ( | ||
SELECT | ||
date, | ||
token, | ||
SUM(revenue_native) AS revenue_native | ||
FROM {{ ref('fact_maple_revenue') }} | ||
GROUP BY 1, 2 | ||
) | ||
, token_incentives as ( | ||
SELECT | ||
DATE(block_timestamp) AS date, | ||
token, | ||
SUM(incentive_native) AS token_incentives_native | ||
FROM {{ ref('fact_maple_token_incentives') }} | ||
GROUP BY 1, 2 | ||
) | ||
, tvl as ( | ||
SELECT | ||
date, | ||
asset as token, | ||
SUM(tvl_native) AS tvl_native | ||
FROM {{ ref('fact_maple_agg_tvl') }} | ||
GROUP BY 1, 2 | ||
) | ||
, treasury as ( | ||
SELECT | ||
date, | ||
token, | ||
SUM(native_balance) AS treasury_value_native | ||
FROM {{ ref('fact_maple_treasury') }} | ||
GROUP BY 1, 2 | ||
) | ||
, treasury_native as ( | ||
SELECT | ||
date, | ||
token, | ||
SUM(native_balance) AS treasury_native | ||
FROM {{ ref('fact_maple_treasury') }} | ||
WHERE token = 'MPL' | ||
GROUP BY 1, 2 | ||
) | ||
, net_treasury as ( | ||
SELECT | ||
date, | ||
token, | ||
SUM(native_balance) AS net_treasury_value | ||
FROM {{ ref('fact_maple_treasury') }} | ||
WHERE token <> 'MPL' | ||
GROUP BY 1, 2 | ||
) | ||
|
||
SELECT | ||
coalesce(fees.date, revenues.date, token_incentives.date, tvl.date, treasury.date) as date, | ||
coalesce(fees.token, revenues.token, token_incentives.token, tvl.token, treasury.token) as token, | ||
fees.fees_native as interest_fees_native, | ||
fees.platform_fees_native as platform_fees_native, | ||
fees.delegate_fees_native as delegate_fees_native, | ||
fees.fees_native - fees.platform_fees_native - fees.delegate_fees_native as supply_side_revenue_native, | ||
supply_side_revenue_native as total_supply_side_revenue_native, | ||
revenues.revenue_native, | ||
token_incentives.token_incentives_native, | ||
token_incentives.token_incentives_native as expenses_native, | ||
revenues.revenue_native - token_incentives.token_incentives_native as protocol_earnings_native | ||
, tvl.tvl_native | ||
, tvl.tvl_native as net_deposits_native | ||
, treasury.treasury_value_native | ||
, treasury_native.treasury_native | ||
, net_treasury.net_treasury_value | ||
FROM | ||
fees | ||
full join revenues using(date, token) | ||
full join token_incentives using(date, token) | ||
full join tvl using(date, token) | ||
full join treasury using(date, token) | ||
full join treasury_native using(date, token) | ||
full join net_treasury using(date, token) | ||
WHERE coalesce(fees.date, revenues.date, token_incentives.date, tvl.date, treasury.date) < to_date(sysdate()) |
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.