Skip to content

Commit

Permalink
Merge branch 'main' into Spectra-price-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-dude authored Jan 8, 2025
2 parents 8694522 + b7cd0fb commit f9cf79c
Show file tree
Hide file tree
Showing 155 changed files with 4,381 additions and 586 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Contributions in the form of issues and pull requests are very much welcome here

## [BETA] Pre-push hooks

UPDATE: These pre-push hooks require running `dbt compile` which is a fairly slow step due to the size of our project. We intend to rewrite these hooks to be more efficient but for the time being they remain cumbersome. Feel free to use them if you find them useful but the same checks will run in a Github Action when you commit your code. Feel free to uninstall if they do not bring joy, we'll let wizards know when we think we've improved them enought to warrant making them part of the general development flow.
UPDATE: These pre-push hooks require running `dbt compile` which is a fairly slow step due to the size of our project. We intend to rewrite these hooks to be more efficient but for the time being they remain cumbersome. Feel free to use them if you find them useful but the same checks will run in a Github Action when you commit your code. Feel free to uninstall if they do not bring joy, we'll let wizards know when we think we've improved them enough to warrant making them part of the general development flow.

We are testing out adding pre-push hooks to our workflow. The goal is to catch common errors before code is pushed and
streamline the pull request review process.
Expand Down Expand Up @@ -126,13 +126,13 @@ example custom test:
```sql
with unit_test1 as
(select
case when col1 == 2 and col2 == 'moon' then True else False end as test
case when col1 = 2 and col2 = 'moon' then True else False end as test
from {{ ref('mock_table' )}}
where tx_id = '102'),

unit_test2 as
(select
case when col1 == 2 and col2 == 'moon' then True else False end as test
case when col1 = 2 and col2 = 'moon' then True else False end as test
from {{ ref('mock_table' )}}
where tx_id = '103'),

Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"
numpy = "2.0.12"
pre-commit = "2.20.0"
pytest = "7.1.3"
dbt-trino = "1.8.2"
dbt-trino = "1.9.0"

[requires]
python_version = "3.9"
python_version = "3.9"
209 changes: 98 additions & 111 deletions Pipfile.lock

Large diffs are not rendered by default.

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
Expand Up @@ -107,6 +107,7 @@
'PenguinStrategyForLPb',
'PlatypusStrategy',
'SonicStrategyForSA',
'StableJackStrategy',
'StableVaultStrategyForS3D',
'StableVaultStrategyForS3F',
'StargateStrategyForLP',
Expand All @@ -115,6 +116,7 @@
'StormStrategyForSA',
'SuStrategyV2',
'SynapseStrategy',
'TokenMillStrategy',
'UnipoolStrategyV1',
'UspPlatypusStrategy',
'Vault',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ existing_contracts AS (
{% endif -%}

new_transfers AS (
SELECT
s.contract_address
, s.block_time
, s.block_number
, s.user_address
, s.net_transfer_amount
FROM (
{%- for strategy in yield_yak_strategies(blockchain) %}
SELECT
s.contract_address
Expand All @@ -40,19 +47,8 @@ new_transfers AS (
, SUM(u.net_transfer_amount) AS net_transfer_amount
FROM {{ source(namespace_blockchain, strategy + '_evt_Transfer') }} s
CROSS JOIN UNNEST(ARRAY[s."from", s.to], ARRAY[-1 * CAST(s.value AS INT256), CAST(s.value AS INT256)]) AS u(user_address, net_transfer_amount)
{%- if is_incremental() %}
LEFT JOIN existing_contracts c
ON c.contract_address = s.contract_address
WHERE
(({{ incremental_predicate('s.evt_block_time') }}
AND s.evt_block_time > c.max_from_time)
OR c.contract_address IS NULL) -- This line allows for new contract_addresses being appended that were not already included in previous runs but also allows their entire historical data to be loaded
AND s."from" != s."to"
{%- endif %}
{%- if not is_incremental() %}
WHERE
s."from" != s."to"
{%- endif %}
GROUP BY
s.contract_address
, s.evt_block_time
Expand All @@ -63,6 +59,15 @@ new_transfers AS (
UNION ALL
{%- endif -%}
{%- endfor %}
) s
{%- if is_incremental() %}
LEFT JOIN existing_contracts c
ON c.contract_address = s.contract_address
WHERE
({{ incremental_predicate('s.block_time') }}
AND s.block_time > c.max_from_time)
OR c.contract_address IS NULL -- This line allows for new contract_addresses being appended that were not already included in previous runs but also allows their entire historical data to be loaded
{%- endif %}
),

combined_table AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Because of that, the `alm.trades` design mimics the one used for `dex.trades`.

### Data Flow Architecture

As previously said, the architecture of `alm.trades` mimics the one of `dex.trades`. Because of that, [this diagram](https://github.com/duneanalytics/spellbook/blob/main/models/_sector/dex/readme.md#data-flow-architecture) can be taken as a reference.
As previously said, the architecture of `alm.trades` mimics the one of `dex.trades`. Because of that, [this diagram](https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/dex/models/trades/readme.md) can be taken as a reference.
In `alm.trades`, the 2 macros used are:
- `arrakis_compatible_v2_trades`: which tracks all the Uniswap V3 LP positions (timestamp, liquidity, and tick information) minted by Arrakis Finance vaults, and then derives the volume served for each swap based on the price movement of the pool.
- `add_pool_price_usd`: which uses `prices.usd` to populate the pool price in USD, so the volume served can be expressed in USD terms.
Expand Down
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
Loading

0 comments on commit f9cf79c

Please sign in to comment.