Skip to content

Commit

Permalink
Merge branch 'op-swaap' of https://github.com/LamprosLabsDAO/spellbook
Browse files Browse the repository at this point in the history
…into op-swaap
  • Loading branch information
Jason4276 committed Jan 21, 2025
2 parents 6a7d318 + 55ae318 commit bb9ee9b
Show file tree
Hide file tree
Showing 25 changed files with 1,049 additions and 23 deletions.
16 changes: 8 additions & 8 deletions dbt_macros/shared/balancer/balancer_liquidity_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ WITH pool_labels AS (
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
('{{blockchain}}' != 'fantom' OR
('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757))) --broken price feeds
AND blockchain = '{{blockchain}}'
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down Expand Up @@ -339,10 +339,10 @@ WITH pool_labels AS (
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
('{{blockchain}}' != 'fantom' OR
('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757))) --broken price feeds
AND blockchain = '{{blockchain}}'
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down
14 changes: 10 additions & 4 deletions dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ WITH pool_labels AS (

dex_prices_1 AS (
SELECT
date_trunc('day', hour) AS DAY,
date_trunc('day', HOUR) AS DAY,
contract_address AS token,
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE blockchain = '{{blockchain}}'
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down Expand Up @@ -213,12 +216,15 @@ WITH pool_labels AS (

dex_prices_1 AS (
SELECT
date_trunc('day', hour) AS DAY,
date_trunc('day', HOUR) AS DAY,
contract_address AS token,
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE blockchain = '{{blockchain}}'
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ WITH
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
{% if is_incremental() %}
WHERE {{ incremental_predicate('hour') }}
AND {{ incremental_predicate('hour') }}
{% endif %}
GROUP BY 1, 2
HAVING sum(sample_size) > 3
Expand Down Expand Up @@ -212,8 +216,12 @@ WITH
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
{% if is_incremental() %}
WHERE {{ incremental_predicate('hour') }}
AND {{ incremental_predicate('hour') }}
{% endif %}
GROUP BY 1, 2
HAVING sum(sample_size) > 3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2

models:
- name: uniswap_pools_optimism_balances
description: "Tracks OP token balances in Uniswap pools on Optimism."
meta:
blockchain: optimism
sector: DEX
project: uniswap
contributors: jason
config:
tags: ['optimism', 'op_token', 'balances', 'uniswap','pools']
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- pool_address
- snapshot_day
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{
config(
schema = 'uniswap_pools_optimism',
alias = 'balances',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['pool_address', 'snapshot_day'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.snapshot_day')]
)
}}

with op_addresses as (
select
pool as address,
token0,
token1,
0x4200000000000000000000000000000000000042 as token_address,
fee as fee_tier,
creation_block_time as creation_time
from
{{ source('uniswap_v3_optimism', 'pools') }}
where
token0 = 0x4200000000000000000000000000000000000042
or token1 = 0x4200000000000000000000000000000000000042
),

filtered_balances as (
{{ balances_incremental_subset_daily(
blockchain='optimism',
start_date='2021-11-11',
address_token_list = 'op_addresses'
) }}
)

select
p.address as pool_address,
p.token0 as token0,
p.token1 as token1,
p.fee_tier,
p.creation_time,
coalesce(b.balance, 0) as op_balance,
coalesce(b.day, current_date) as snapshot_day
from
filtered_balances b
left join
op_addresses p on b.address = p.address
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ WITH v2_pools AS(
ON c.evt_tx_hash = cc.call_tx_hash
AND bytearray_substring(c.poolId, 1, 20) = cc.output_0
CROSS JOIN UNNEST(cc.tokens) AS t(tokens)

UNION ALL

SELECT
c.poolId AS pool_id,
t.tokens AS token_address,
0 AS normalized_weight,
cc.symbol,
'ECLP' AS pool_type,
cc.name
FROM {{ source('beethoven_x_v2_sonic', 'Vault_evt_PoolRegistered') }} c
INNER JOIN {{ source('gyroscope_sonic', 'GyroECLPPoolFactory_call_create') }} cc
ON c.evt_tx_hash = cc.call_tx_hash
AND bytearray_substring(c.poolId, 1, 20) = cc.output_0
CROSS JOIN UNNEST(cc.tokens) AS t(tokens)

),

settings AS (
Expand All @@ -65,7 +81,7 @@ settings AS (
SELECT
'sonic' AS blockchain,
bytearray_substring(pool_id, 1, 20) AS address,
CASE WHEN pool_type IN ('stable')
CASE WHEN pool_type IN ('stable', 'ECLP')
THEN lower(pool_symbol)
ELSE lower(concat(array_join(array_agg(token_symbol ORDER BY token_symbol), '/'), ' ',
array_join(array_agg(cast(norm_weight AS varchar) ORDER BY token_symbol), '/')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ v3 AS(
)
}})


SELECT * FROM v2

UNION
Expand Down
3 changes: 3 additions & 0 deletions dbt_subprojects/daily_spellbook/models/evms/evms_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
, "fantom"
, "flare"
, "gnosis"
, "ink"
, "kaia"
, "linea"
, "nova"
Expand Down Expand Up @@ -99,4 +100,6 @@ FROM (
, (88, 'viction', 'Viction', 'Layer 1', NULL, 'VIC', 0xC054751BdBD24Ae713BA3Dc9Bd9434aBe2abc1ce, 'https://vicscan.xyz/', timestamp '2018-12-14 07:50:20', NULL, NULL, NULL, true)
, (21000000, 'corn', 'Corn', 'Layer 1', NULL, 'BTCN', NULL, 'https://cornscan.io/', timestamp '2024-11-19 10:29:11', NULL, NULL, NULL, true)
, (146, 'sonic', 'Sonic', 'Layer 1', NULL, 'SONIC', NULL, 'https://sonicscan.org/', timestamp '2024-12-01 00:00', NULL, NULL, NULL, true)
, (57073, 'ink', 'Ink', 'Layer 2', 'Optimistic Rollup', 'ETH', 0x4200000000000000000000000000000000000006, 'https://explorer.inkonchain.com/', timestamp '2024-12-06 15:20', 'OP Stack', 'Ethereum Blobs', 'Ethereum', true)
) AS temp_table (chain_id, blockchain, name, chain_type, rollup_type, native_token_symbol, wrapped_native_token_address, explorer_link, first_block_time, codebase, data_availability, settlement, is_on_dune)

Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ models:

- name: evms_info
meta:
blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, goerli, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei, ronin
blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, goerli, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei, ronin, ink
sector: evms
contributors: hildobby
config:
Expand Down
4 changes: 2 additions & 2 deletions dbt_subprojects/tokens/models/prices/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ models:

- name: prices_tokens
meta:
blockchain: arbitrum, avalanche_c, gnosis, polygon, optimism, ethereum, bnb, solana, fantom, celo, base, zksync, zora, linea, zkevm, blast, sei, nova, worldchain, kaia, ronin
blockchain: arbitrum, avalanche_c, gnosis, polygon, optimism, ethereum, bnb, solana, fantom, celo, base, zksync, zora, linea, zkevm, blast, sei, nova, worldchain, kaia, ronin, ink
sector: prices
contributors: aalan3, hildobby, pipistrella, viniabussafi, jeff-dude, hosuke
config:
Expand All @@ -171,7 +171,7 @@ models:

- name: prices_native_tokens
meta:
blockchain: arbitrum, avalanche_c, gnosis, polygon, optimism, ethereum, bnb, solana, fantom, celo, zksync, zora, sei, nova, worldchain, kaia, ronin
blockchain: arbitrum, avalanche_c, gnosis, polygon, optimism, ethereum, bnb, solana, fantom, celo, zksync, zora, sei, nova, worldchain, kaia, ronin, ink
sector: prices
contributors: aalan3, jeff-dude
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ FROM
('renbtc-renbtc', 'avalanche_c', 'renBTC', 0xdbf31df14b66535af65aac99c32e9ea844e14501, 8),
('arena-the-arena', 'avalanche_c', 'ARENA', 0xb8d7710f7d8349a506b75dd184f05777c82dad0c, 18),
('zro-layerzero', 'avalanche_c', 'ZRO', 0x6985884c4392d348587b19cb9eaaf157f13271cd, 18),
('beam-beam-eth', 'avalanche_c', 'BEAM', 0x62d0a8458ed7719fdaf978fe5929c6d342b0bfce, 18)
('beam-beam-eth', 'avalanche_c', 'BEAM', 0x62d0a8458ed7719fdaf978fe5929c6d342b0bfce, 18),
('ggp-gogopool', 'avalanche_c', 'GGP', 0x69260B9483F9871ca57f81A90D91E2F96c2Cd11d, 18)

) as temp (token_id, blockchain, symbol, contract_address, decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,8 @@ FROM
('usr-resolv-usr', 'ethereum', 'USR', 0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110, 18),
('sovrn-sovrun','ethereum', 'SOVRN', 0x031B8d752d73d7Fe9678ACEf26e818280D0646b4, 18),
('apw-spectra','ethereum', 'APW', 0x4104b135dbc9609fc1a9490e61369036497660c8, 18),
('wagmi5-wagmi', 'ethereum', 'WAGMI', 0x92CC36D66e9d739D50673d1f27929a371FB83a67, 18)
('wagmi5-wagmi', 'ethereum', 'WAGMI', 0x92CC36D66e9d739D50673d1f27929a371FB83a67, 18),
('deusd-elixir-deusd','ethereum', 'DEUSD', 0x15700b564ca08d9439c58ca5053166e8317aa138, 18)
) as temp (token_id, blockchain, symbol, contract_address, decimals)
where contract_address not in (
-- bad price feeds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ FROM
('giv-giv', 'gnosis', 'GIV', 0x4f4F9b8D5B4d0Dc10506e5551B0513B61fD59e75, 18),
('usdc-usd-coin', 'gnosis', 'USDC.e', 0x2a22f9c3b484c3629090feed35f17ff8f88f76f0, 6),
('ageur-ageur', 'gnosis', 'agEUR', 0x4b1e2c2762667331bc91648052f646d1b0d35984, 18),
('brla-brla-digital-brla', 'gnosis', 'BRLA', 0xFECB3F7c54E2CAAE9dC6Ac9060A822D47E053760, 18)
('brla-brla-digital-brla', 'gnosis', 'BRLA', 0xFECB3F7c54E2CAAE9dC6Ac9060A822D47E053760, 18),
('gyd-gyro-dollar','gnosis','GYD',0xca5d8f8a8d49439357d3cf46ca2e720702f132b8, 18),
('reth-rocket-pool-eth', 'gnosis', 'rETH', 0xc791240d1f2def5938e2031364ff4ed887133c3d, 18)
) as temp (token_id, blockchain, symbol, contract_address, decimals)
29 changes: 29 additions & 0 deletions dbt_subprojects/tokens/models/prices/ink/_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: 2

models:
- name: prices_ink_tokens
meta:
blockchain: ink
sector: prices
contributors: jeff-dude
config:
tags: ['prices', 'tokens', 'usd', 'ink']
description: "Price tokens on ink EVM chain"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- contract_address
columns:
- name: token_id
description: "Id of the token at coinpaprika. This id is required to pull the price feed data. NOTE: Not all tokens are listed at coinpaprika - consider using price data from DEX sources in this case or submit a listing request at coinpaprika."
- name: blockchain
description: "Native blockchain of the token, if any"
data_tests:
- accepted_values:
values: [ "ink" ]
- name: contract_address
description: "Contract address of the token, if any"
- name: symbol
description: "Token symbol"
- name: decimals
description: "Number of decimals for the token contract"
23 changes: 23 additions & 0 deletions dbt_subprojects/tokens/models/prices/ink/prices_ink_tokens.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% set blockchain = 'ink' %}

{{ config(
schema = 'prices_' + blockchain,
alias = 'tokens',
materialized = 'table',
file_format = 'delta',
tags = ['static']
)
}}

SELECT
token_id
, '{{ blockchain }}' as blockchain
, symbol
, contract_address
, decimals
FROM
(
VALUES
('weth-weth', 'WETH', 0x4200000000000000000000000000000000000006, 18)
, ('usdc-usd-coin', 'USDC.e', 0xF1815bd50389c46847f0Bda824eC8da914045D14, 6)
) as temp (token_id, symbol, contract_address, decimals)
2 changes: 2 additions & 0 deletions dbt_subprojects/tokens/models/prices/prices_tokens.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
, "fantom"
, "flare"
, "gnosis"
, "ink"
, "kaia"
, "linea"
, "nova"
Expand Down Expand Up @@ -74,6 +75,7 @@ ref('prices_native_tokens')
,ref('prices_viction_tokens')
,ref('prices_corn_tokens')
,ref('prices_sonic_tokens')
,ref('prices_ink_tokens')
] %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ WITH trusted_tokens AS (
, ('gnosis', 0x8e5bbbb09ed1ebde8674cda39a0c169401db4252)
, ('gnosis', 0x44fa8e6f47987339850636f88629646662444217)
, ('gnosis', 0xdd96b45877d0e8361a4ddb732da741e97f3191ff)
, ('ink', 0x4200000000000000000000000000000000000006)
, ('ink', 0xf1815bd50389c46847f0bda824ec8da914045d14)
, ('kaia', 0x5c13e303a62fc5dedf5b52d66873f2e59fedadc2)
, ('kaia', 0x608792deb376cce1c9fa4d0e6b7b44f507cffa6a)
, ('kaia', 0x19aac5f612f524b754ca7e7c41cbfa2e981a4432)
Expand Down
4 changes: 2 additions & 2 deletions dbt_subprojects/tokens/models/tokens/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ version: 2
models:
- name: tokens_erc20
meta:
blockchain: arbitrum, avalanche_c, bnb, ethereum, gnosis, mantle, optimism, fantom, polygon, base, blast, sepolia, sei, nova, worldchain, kaia, ronin, boba, flare, viction, sonic
blockchain: arbitrum, avalanche_c, bnb, ethereum, gnosis, mantle, optimism, fantom, polygon, base, blast, sepolia, sei, nova, worldchain, kaia, ronin, boba, flare, viction, sonic, ink
sector: tokens
contributors: hildobby, 0xManny, dot2dotseurat, soispoke, mtitus6, wuligy, angus_1, Henrystats, viniabussafi, jeff-dude, rantum, hosuke, irishlatte19
config:
tags: ['tokens','erc20', 'arbitrum', 'avalanche_c', 'bnb', 'ethereum', 'gnosis', 'mantle', 'optimism', 'fantom', 'base', 'blast', 'sei', 'nova', 'linea', 'worldchain', 'kaia', 'ronin', 'boba', 'flare', 'viction', 'sonic']
tags: ['tokens','erc20', 'arbitrum', 'avalanche_c', 'bnb', 'ethereum', 'gnosis', 'mantle', 'optimism', 'fantom', 'base', 'blast', 'sei', 'nova', 'linea', 'worldchain', 'kaia', 'ronin', 'boba', 'flare', 'viction', 'sonic', 'ink']

description: >
Crosschain ERC20 tokens
Expand Down
21 changes: 21 additions & 0 deletions dbt_subprojects/tokens/models/tokens/ink/_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2

models:
- name: tokens_ink_erc20
meta:
blockchain: ink
sector: tokens
project: erc20
contributors: jeff-dude
config:
tags: ['table', 'erc20', 'ink']
description: "ERC20 Token Addresses, Symbols and Decimals"
columns:
- name: contract_address
description: "ERC20 token contract address"
data_tests:
- unique
- name: symbol
description: "ERC20 token symbol"
- name: decimals
description: "Number of decimals, refers to how divisible an ERC20 token can be"
Loading

0 comments on commit bb9ee9b

Please sign in to comment.