Skip to content

Commit

Permalink
update feeds | add base | create ocr macro
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonJon committed May 4, 2024
1 parent e66ec7e commit 41fdaae
Show file tree
Hide file tree
Showing 50 changed files with 938 additions and 867 deletions.
89 changes: 89 additions & 0 deletions macros/models/_project/chainlink/chainlink_ocr_macro.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{% macro
chainlink_ocr_gas_transmission_logs(
blockchain
)
%}

SELECT
'{{blockchain}}' as blockchain,
block_hash,
contract_address,
data,
topic0,
topic1,
topic2,
topic3,
tx_hash,
block_number,
block_time,
index,
tx_index
FROM
{{ source(blockchain, 'logs') }} logs
WHERE
topic0 = 0xf6a97944f31ea060dfde0566e4167c1a1082551e64b60ecb14d599a9d023d451


{% endmacro %}

# ---------------------------------------------

{% macro
chainlink_ocr_fulfilled_transactions(
blockchain,
gas_token_symbol,
gas_price_column
)
%}

{% set incremental_interval = '7' %}

WITH
network_usd AS (
SELECT
minute as block_time,
price as usd_amount
FROM
{{ source('prices', 'usd') }} price
WHERE
symbol = '{{gas_token_symbol}}'
{% if is_incremental() %}
AND minute >= date_trunc('day', now() - interval '{{incremental_interval}}' day)
{% endif %}
),
ocr_fulfilled_transactions AS (
SELECT
tx.hash as tx_hash,
tx.index as tx_index,
MAX(tx.block_time) as block_time,
cast(date_trunc('month', MAX(tx.block_time)) as date) as date_month,
tx."from" as "node_address",
MAX(
(cast((gas_used) as double) / 1e18) * tx.{{gas_price_column}}
) as token_amount,
MAX(network_usd.usd_amount) as usd_amount
FROM
{{ source(blockchain, 'transactions') }} tx
RIGHT JOIN {{ ref('chainlink_' ~ blockchain ~ '_ocr_gas_transmission_logs') }} ocr_gas_transmission_logs ON ocr_gas_transmission_logs.tx_hash = tx.hash
LEFT JOIN network_usd ON date_trunc('minute', tx.block_time) = network_usd.block_time
{% if is_incremental() %}
WHERE tx.block_time >= date_trunc('day', now() - interval '{{incremental_interval}}' day)
{% endif %}
GROUP BY
tx.hash,
tx.index,
tx."from"
)
SELECT
'{{blockchain}}' as blockchain,
block_time,
date_month,
node_address,
token_amount,
usd_amount,
tx_hash,
tx_index
FROM
ocr_fulfilled_transactions

{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,22 @@
post_hook='{{ expose_spells(\'["arbitrum"]\',
"project",
"chainlink",
\'["linkpool_ryan"]\') }}'
\'["linkpool_jon"]\') }}'
)
}}

{% set incremental_interval = '7' %}

WITH
arbitrum_usd AS (
SELECT
minute as block_time,
price as usd_amount
FROM
{{ source('prices', 'usd') }} price
WHERE
symbol = 'ETH'
{% if is_incremental() %}
AND minute >= date_trunc('day', now() - interval '{{incremental_interval}}' day)
{% endif %}
),
ocr_fulfilled_transactions AS (
SELECT
tx.hash as tx_hash,
tx.index as tx_index,
MAX(tx.block_time) as block_time,
cast(date_trunc('month', MAX(tx.block_time)) as date) as date_month,
tx."from" as "node_address",
MAX(
(cast((gas_used) as double) / 1e18) * effective_gas_price
) as token_amount,
MAX(arbitrum_usd.usd_amount) as usd_amount
FROM
{{ source('arbitrum', 'transactions') }} tx
RIGHT JOIN {{ ref('chainlink_arbitrum_ocr_gas_transmission_logs') }} ocr_gas_transmission_logs ON ocr_gas_transmission_logs.tx_hash = tx.hash
LEFT JOIN arbitrum_usd ON date_trunc('minute', tx.block_time) = arbitrum_usd.block_time
{% if is_incremental() %}
WHERE tx.block_time >= date_trunc('day', now() - interval '{{incremental_interval}}' day)
{% endif %}
GROUP BY
tx.hash,
tx.index,
tx."from"
)
ocr_fulfilled_transactions AS (
{{
chainlink_ocr_fulfilled_transactions(
blockchain = 'arbitrum',
gas_token_symbol = 'ETH',
gas_price_column = 'effective_gas_price',
)
}}
)

SELECT
'arbitrum' as blockchain,
block_time,
date_month,
node_address,
token_amount,
usd_amount,
tx_hash,
tx_index
*
FROM
ocr_fulfilled_transactions
ocr_fulfilled_transactions
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
post_hook='{{ expose_spells(\'["arbitrum"]\',
"project",
"chainlink",
\'["linkpool_ryan"]\') }}'
\'["linkpool_ryan","linkpool_jon"]\') }}'
)
}}

WITH
ocr_gas_transmission_logs AS (
{{
chainlink_ocr_gas_transmission_logs(
blockchain = 'arbitrum'
)
}}
)

SELECT
'arbitrum' as blockchain,
block_hash,
contract_address,
data,
topic0,
topic1,
topic2,
topic3,
tx_hash,
block_number,
block_time,
index,
tx_index
*
FROM
{{ source('arbitrum', 'logs') }} logs
WHERE
topic0 = 0xf6a97944f31ea060dfde0566e4167c1a1082551e64b60ecb14d599a9d023d451
ocr_gas_transmission_logs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{
config(

alias='ocr_operator_admin_meta',
materialized = 'view',
post_hook='{{ expose_spells(\'["arbitrum"]\',
Expand Down Expand Up @@ -31,10 +30,11 @@ SELECT admin_address, operator_name FROM (VALUES
(0x9efa0A617C0552F1558c95993aA8b8A68b3e709C, '{{dextrac}}'),
(0x15918ff7f6C44592C81d999B442956B07D26CC44, '{{fiews}}'),
(0x6eF38c3d1D85B710A9e160aD41B912Cb8CAc2589, '{{frameworkventures}}'),
(0xdD831352762e9de7ad5a264990e1bB9F87A6Fc21, '{{inotel}}'),
(0xB8C6E43f37E04A2411562a13c1C48B3ad5975cf4, '{{inotel}}'),
(0x4564A9c6061f6f1F2Eadb954B1b3C241D2DC984e, '{{linkforest}}'),
(0x797de2909991C66C66D8e730C8385bbab8D18eA6, '{{linkpool}}'),
(0xDF812B91D8bf6DF698BFD1D8047839479Ba63420, '{{linkpool}}'),
(0x797de2909991C66C66D8e730C8385bbab8D18eA6, '{{linkpool}}'),
(0x14f94049397C3F1807c45B6f854Cb5F36bC4393B, '{{linkriver}}'),
(0x4dc81f63CB356c1420D4620414f366794072A3a8, '{{matrixedlink}}'),
(0x0921E157b690c4F89F7C2a210cFd8bF3964F6776, '{{northwestnodes}}'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{
config(

alias='ocr_operator_node_meta',
materialized = 'view',
post_hook='{{ expose_spells(\'["arbitrum"]\',
Expand Down
Loading

0 comments on commit 41fdaae

Please sign in to comment.