Skip to content

Commit

Permalink
Merge branch 'main' into sonictokens
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-dude authored Jan 7, 2025
2 parents e4b0230 + 92626ab commit 1ef31d4
Show file tree
Hide file tree
Showing 58 changed files with 1,835 additions and 390 deletions.
2 changes: 1 addition & 1 deletion dbt_subprojects/daily_spellbook/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Daily Spellbook

This is a DBT sub project for the the main models of Spellbook that runs on a daily candence.
This is a DBT sub project for the main models of Spellbook that runs on a daily cadence.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{{config(

alias = 'balancer_v2_gauges',
alias = 'balancer_gauges',
post_hook='{{ expose_spells(\'["ethereum", "arbitrum", "optimism", "polygon", "avalanche_c", "base", "gnosis", "zkevm"]\',
"sector",
"labels",
\'["jacektrocinski", "viniabussafi"]\') }}')}}

{% set gauges_models = [
ref('labels_balancer_v2_gauges_ethereum')
, ref('labels_balancer_v2_gauges_polygon')
, ref('labels_balancer_v2_gauges_arbitrum')
, ref('labels_balancer_v2_gauges_optimism')
, ref('labels_balancer_v2_gauges_avalanche_c')
, ref('labels_balancer_v2_gauges_base')
, ref('labels_balancer_v2_gauges_gnosis')
, ref('labels_balancer_v2_gauges_zkevm')
ref('labels_balancer_gauges_ethereum')
, ref('labels_balancer_gauges_polygon')
, ref('labels_balancer_gauges_arbitrum')
, ref('labels_balancer_gauges_optimism')
, ref('labels_balancer_gauges_avalanche_c')
, ref('labels_balancer_gauges_base')
, ref('labels_balancer_gauges_gnosis')
, ref('labels_balancer_gauges_zkevm')
] %}

SELECT *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{config(

alias = 'balancer_v2_gauges_arbitrum',
alias = 'balancer_gauges_arbitrum',
post_hook='{{ expose_spells(\'["arbitrum"]\',
"sector",
"labels",
Expand All @@ -13,12 +12,12 @@ SELECT distinct
pools.address AS pool_address,
streamer.gauge AS child_gauge_address,
'arb:' || pools.name AS name,
'balancer_v2_gauges' AS category,
'balancer_gauges' AS category,
'balancerlabs' AS contributor,
'query' AS source,
TIMESTAMP '2022-01-13' AS created_at,
NOW() AS updated_at,
'balancer_v2_gauges_arbitrum' AS model_name,
'balancer_gauges_arbitrum' AS model_name,
'identifier' AS label_type
FROM
{{ source('balancer_ethereum', 'ArbitrumRootGaugeFactory_evt_ArbitrumRootGaugeCreated') }} gauge
Expand All @@ -34,12 +33,12 @@ SELECT distinct
pools.address AS pool_address,
streamer.gauge AS child_gauge_address,
'arb:' || pools.name AS name,
'balancer_v2_gauges' AS category,
'balancer_gauges' AS category,
'balancerlabs' AS contributor,
'query' AS source,
TIMESTAMP '2022-01-13' AS created_at,
NOW() AS updated_at,
'balancer_v2_gauges_arbitrum' AS model_name,
'balancer_gauges_arbitrum' AS model_name,
'identifier' AS label_type
FROM
{{ source('balancer_ethereum', 'CappedArbitrumRootGaugeFactory_evt_GaugeCreated') }} gauge
Expand All @@ -55,46 +54,86 @@ SELECT distinct
pools.address AS pool_address,
child.output_0 AS child_gauge_address,
'arb:' || pools.name AS name,
'balancer_v2_gauges' AS category,
'balancer_gauges' AS category,
'balancerlabs' AS contributor,
'query' AS source,
TIMESTAMP '2022-01-13' AS created_at,
NOW() AS updated_at,
'balancer_v2_gauges_arbitrum' AS model_name,
'balancer_gauges_arbitrum' AS model_name,
'identifier' AS label_type
FROM {{ source('balancer_ethereum', 'CappedArbitrumRootGaugeFactory_call_create') }} call
LEFT JOIN {{ source('balancer_arbitrum', 'ChildChainGaugeFactory_call_create') }} child ON child.output_0 = call.recipient
LEFT JOIN {{ source('labels', 'balancer_v2_pools_arbitrum') }} pools ON pools.address = child.pool),

gauges AS(
SELECT * FROM reward_gauges
WHERE name IS NOT NULL
UNION ALL
SELECT * FROM child_gauges
WHERE name IS NOT NULL),
SELECT
*
FROM reward_gauges
WHERE name IS NOT NULL

UNION ALL

controller AS( --to allow filtering for active gauges only
SELECT
c.evt_tx_hash,
c.evt_index,
c.evt_block_time,
c.evt_block_number,
c.addr AS address,
ROW_NUMBER() OVER (PARTITION BY g.pool_address ORDER BY evt_block_time DESC) AS rn
FROM {{ source('balancer_ethereum', 'GaugeController_evt_NewGauge') }} c
INNER JOIN gauges g ON g.address = c.addr
)
SELECT
*
FROM child_gauges
WHERE name IS NOT NULL),

kill_unkill_1 AS(
SELECT
contract_address,
call_block_time,
'kill' AS action
FROM {{ source('balancer_ethereum', 'ArbitrumRootGauge_call_killGauge') }}
WHERE call_success

UNION ALL

SELECT
contract_address,
call_block_time,
'kill' AS action
FROM {{ source('balancer_ethereum', 'CappedArbitrumRootGauge_call_killGauge') }}
WHERE call_success

UNION ALL

SELECT
contract_address,
call_block_time,
'unkill' AS action
FROM {{ source('balancer_ethereum', 'ArbitrumRootGauge_call_initialize') }}
WHERE call_success

UNION ALL

SELECT
contract_address,
call_block_time,
'unkill' AS action
FROM {{ source('balancer_ethereum', 'CappedArbitrumRootGauge_call_initialize') }}
WHERE call_success
),

kill_unkill AS(
SELECT
contract_address,
call_block_time,
action,
ROW_NUMBER() OVER(PARTITION BY contract_address ORDER BY call_block_time DESC) AS rn
FROM kill_unkill_1
)
SELECT DISTINCT
g.blockchain
, g.address
, g.pool_address
, g.child_gauge_address
, g.name
, CASE WHEN c.rn = 1
, CASE WHEN k.action = 'kill'
THEN 'inactive'
WHEN k.action = 'unkill'
THEN 'active'
ELSE 'inactive'
END AS status
ELSE 'active'
END AS status
, g.category
, g.contributor
, g.source
Expand All @@ -103,4 +142,4 @@ INNER JOIN gauges g ON g.address = c.addr
, g.model_name
, g.label_type
FROM gauges g
INNER JOIN controller c ON g.address = c.address
LEFT JOIN kill_unkill k ON g.address = k.contract_address AND k.rn = 1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{config(

alias = 'balancer_v2_gauges_avalanche_c',
alias = 'balancer_gauges_avalanche_c',
post_hook='{{ expose_spells(\'["avalanche_c"]\',
"sector",
"labels",
Expand All @@ -13,39 +12,56 @@ SELECT distinct
pools.address AS pool_address,
child.output_0 AS child_gauge_address,
'ava:' || pools.name AS name,
'balancer_v2_gauges' AS category,
'balancer_gauges' AS category,
'balancerlabs' AS contributor,
'query' AS source,
TIMESTAMP '2022-01-13' AS created_at,
NOW() AS updated_at,
'balancer_v2_gauges_avalanche_c' AS model_name,
'balancer_gauges_avalanche_c' AS model_name,
'identifier' AS label_type
FROM {{ source('balancer_ethereum', 'AvalancheRootGaugeFactory_call_create') }} call
LEFT JOIN {{ source('balancer_avalanche_c', 'ChildChainGaugeFactory_call_create') }} child ON child.output_0 = call.recipient
LEFT JOIN {{ source('labels', 'balancer_v2_pools_avalanche_c') }} pools ON pools.address = child.pool),

controller AS( --to allow filtering for active gauges only
SELECT
c.evt_tx_hash,
c.evt_index,
c.evt_block_time,
c.evt_block_number,
c.addr AS address,
ROW_NUMBER() OVER (PARTITION BY g.pool_address ORDER BY evt_block_time DESC) AS rn
FROM {{ source('balancer_ethereum', 'GaugeController_evt_NewGauge') }} c
INNER JOIN gauges g ON g.address = c.addr
)
kill_unkill_1 AS(
SELECT
contract_address,
call_block_time,
'kill' AS action
FROM {{ source('balancer_ethereum', 'AvalancheRootGauge_call_killGauge') }}
WHERE call_success

UNION ALL

SELECT
contract_address,
call_block_time,
'unkill' AS action
FROM {{ source('balancer_ethereum', 'AvalancheRootGauge_call_initialize') }}
WHERE call_success
),

kill_unkill AS(
SELECT
contract_address,
call_block_time,
action,
ROW_NUMBER() OVER(PARTITION BY contract_address ORDER BY call_block_time DESC) AS rn
FROM kill_unkill_1
)

SELECT DISTINCT
g.blockchain
, g.address
, g.pool_address
, g.child_gauge_address
, g.name
, CASE WHEN c.rn = 1
, CASE WHEN k.action = 'kill'
THEN 'inactive'
WHEN k.action = 'unkill'
THEN 'active'
ELSE 'inactive'
END AS status
ELSE 'active'
END AS status
, g.category
, g.contributor
, g.source
Expand All @@ -54,4 +70,4 @@ INNER JOIN gauges g ON g.address = c.addr
, g.model_name
, g.label_type
FROM gauges g
INNER JOIN controller c ON g.address = c.address
LEFT JOIN kill_unkill k ON g.address = k.contract_address AND k.rn = 1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{config(

alias = 'balancer_v2_gauges_base',
alias = 'balancer_gauges_base',
post_hook='{{ expose_spells(\'["base"]\',
"sector",
"labels",
Expand All @@ -13,39 +12,56 @@ SELECT distinct
pools.address AS pool_address,
child.output_0 AS child_gauge_address,
'base:' || pools.name AS name,
'balancer_v2_gauges' AS category,
'balancer_gauges' AS category,
'balancerlabs' AS contributor,
'query' AS source,
TIMESTAMP '2022-01-13' AS created_at,
NOW() AS updated_at,
'balancer_v2_gauges_base' AS model_name,
'balancer_gauges_base' AS model_name,
'identifier' AS label_type
FROM {{ source('balancer_ethereum', 'BaseRootGaugeFactory_call_create') }} call
LEFT JOIN {{ source('balancer_base', 'ChildChainGaugeFactory_call_create') }} child ON child.output_0 = call.recipient
LEFT JOIN {{ source('labels', 'balancer_v2_pools_base') }} pools ON pools.address = child.pool),

controller AS( --to allow filtering for active gauges only
SELECT
c.evt_tx_hash,
c.evt_index,
c.evt_block_time,
c.evt_block_number,
c.addr AS address,
ROW_NUMBER() OVER (PARTITION BY g.pool_address ORDER BY evt_block_time DESC) AS rn
FROM {{ source('balancer_ethereum', 'GaugeController_evt_NewGauge') }} c
INNER JOIN gauges g ON g.address = c.addr
)
kill_unkill_1 AS(
SELECT
contract_address,
call_block_time,
'kill' AS action
FROM {{ source('balancer_ethereum', 'BaseRootGauge_call_killGauge') }}
WHERE call_success

UNION ALL

SELECT
contract_address,
call_block_time,
'unkill' AS action
FROM {{ source('balancer_ethereum', 'BaseRootGauge_call_initialize') }}
WHERE call_success
),

kill_unkill AS(
SELECT
contract_address,
call_block_time,
action,
ROW_NUMBER() OVER(PARTITION BY contract_address ORDER BY call_block_time DESC) AS rn
FROM kill_unkill_1
)

SELECT DISTINCT
g.blockchain
, g.address
, g.pool_address
, g.child_gauge_address
, g.name
, CASE WHEN c.rn = 1
, CASE WHEN k.action = 'kill'
THEN 'inactive'
WHEN k.action = 'unkill'
THEN 'active'
ELSE 'inactive'
END AS status
ELSE 'active'
END AS status
, g.category
, g.contributor
, g.source
Expand All @@ -54,4 +70,4 @@ INNER JOIN gauges g ON g.address = c.addr
, g.model_name
, g.label_type
FROM gauges g
INNER JOIN controller c ON g.address = c.address
LEFT JOIN kill_unkill k ON g.address = k.contract_address AND k.rn = 1
Loading

0 comments on commit 1ef31d4

Please sign in to comment.