Skip to content

Commit

Permalink
adding vrf fees models (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwes authored and SebMelendez01 committed Sep 9, 2024
1 parent 0b9aaf8 commit c5daf18
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{
config(
materialized="table",
snowflake_warehouse="CHAINLINK",
database="chainlink",
schema="raw",
alias="fact_ethereum_vrf_request_fulfilled",
)
}}


SELECT
'ethereum' as blockchain,
MAX(CAST(v1_request.fee AS double))/1e18 AS token_value,
MAX(v1_fulfilled.block_timestamp) as evt_block_time
FROM
{{ ref('fact_chainlink_ethereum_vrf_v1_random_request_logs') }} v1_request
INNER JOIN {{ ref('fact_chainlink_ethereum_vrf_v1_random_fulfilled_logs') }} v1_fulfilled
ON v1_fulfilled.request_id = v1_request.request_id
GROUP BY
v1_request.tx_hash
UNION

SELECT
'ethereum' as blockchain,
MAX(CAST(v2_fulfilled.payment as double))/1e18 AS token_value,
MAX(v2_fulfilled.block_timestamp) as evt_block_time
FROM
{{ ref('fact_chainlink_ethereum_vrf_v2_random_fulfilled_logs') }} v2_fulfilled
GROUP BY
v2_fulfilled.tx_hash,
v2_fulfilled.event_index
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{
config(
materialized="table",
snowflake_warehouse="CHAINLINK",
database="chainlink",
schema="raw",
alias="fact_ethereum_vrf_request_fulfilled_daily",
)
}}


SELECT
'ethereum' as blockchain,
cast(date_trunc('day', evt_block_time) AS date) AS date_start,
SUM(token_value) as token_amount
FROM
{{ref('fact_chainlink_ethereum_vrf_request_fulfilled')}} vrf_request_fulfilled
GROUP BY
2
ORDER BY
2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{
config(
materialized="table",
snowflake_warehouse="CHAINLINK",
database="chainlink",
schema="raw",
alias="fact_ethereum_vrf_rewards_daily",
)
}}

WITH
link_usd_daily AS (
{{get_coingecko_price_with_latest("chainlink")}}
),
vrf_reward_daily AS (
SELECT
vrf_daily.date_start,
COALESCE(vrf_daily.token_amount, 0) as token_amount,
COALESCE(vrf_daily.token_amount * lud.price, 0) as usd_amount
FROM
{{ref('fact_chainlink_ethereum_vrf_request_fulfilled_daily')}} vrf_daily
LEFT JOIN link_usd_daily lud ON lud.date = vrf_daily.date_start
ORDER BY date_start
)
SELECT
'ethereum' as blockchain,
date_start as date,
token_amount,
usd_amount
FROM
vrf_reward_daily
ORDER BY
2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{
config(
materialized="table",
snowflake_warehouse="CHAINLINK",
database="chainlink",
schema="raw",
alias="fact_ethereum_vrf_v1_random_fulfilled_logs",
)
}}

select
block_timestamp,
tx_hash,
GET_PATH(decoded_log, 'requestId') as request_id
from ethereum_flipside.core.ez_decoded_event_logs
where event_name = 'RandomnessRequestFulfilled'
and contract_address = '0xf0d54349addcf704f77ae15b96510dea15cb7952'
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(
materialized="table",
snowflake_warehouse="CHAINLINK",
database="chainlink",
schema="raw",
alias="fact_ethereum_vrf_v1_random_request_logs",
)
}}

select
block_timestamp,
tx_hash,
origin_from_address as tx_from,
CAST(GET_PATH(decoded_log,'fee') as double) as fee,
GET_PATH(decoded_log, 'requestID') as request_id
from ethereum_flipside.core.ez_decoded_event_logs
where event_name = 'RandomnessRequest'
and contract_address = '0xf0d54349addcf704f77ae15b96510dea15cb7952'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{
config(
materialized="table",
snowflake_warehouse="CHAINLINK",
database="chainlink",
schema="raw",
alias="fact_ethereum_vrf_v2_random_fulfilled_logs",
)
}}

select
block_timestamp,
tx_hash,
event_index,
GET_PATH(decoded_log, 'payment') as payment
from ethereum_flipside.core.ez_decoded_event_logs
where event_name = 'RandomWordsFulfilled'
and contract_address = '0x271682deb8c4e0901d1a1550ad2e64d568e69909'

0 comments on commit c5daf18

Please sign in to comment.