diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/_schema.yml b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/_schema.yml index 15203c33c6f..bbdf3030356 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/_schema.yml @@ -3,7 +3,7 @@ version: 2 models: - name: balancer_v3_erc4626_token_mapping meta: - blockchain: ethereum, gnosis + blockchain: ethereum, gnosis, sonic project: balancer contributors: viniabussafi config: @@ -32,7 +32,7 @@ models: - name: balancer_v3_erc4626_token_prices meta: - blockchain: ethereum, gnosis + blockchain: ethereum, gnosis, sonic project: balancer contributors: viniabussafi config: diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_mapping.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_mapping.sql index 00f666a601e..0e11e3e9d17 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_mapping.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_mapping.sql @@ -10,7 +10,8 @@ {% set balancer_models = [ ref('balancer_v3_ethereum_erc4626_token_mapping'), - ref('balancer_v3_gnosis_erc4626_token_mapping') + ref('balancer_v3_gnosis_erc4626_token_mapping'), + ref('balancer_v3_sonic_erc4626_token_mapping') ] %} SELECT * diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_prices.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_prices.sql index 33553280603..be96770a2d7 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_prices.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/balancer_v3_erc4626_token_prices.sql @@ -11,7 +11,8 @@ {% set balancer_models = [ ref('balancer_v3_ethereum_erc4626_token_prices'), - ref('balancer_v3_gnosis_erc4626_token_prices') + ref('balancer_v3_gnosis_erc4626_token_prices'), + ref('balancer_v3_sonic_erc4626_token_prices') ] %} SELECT * diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/_schema.yml b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/_schema.yml new file mode 100644 index 00000000000..a2fb1d1518b --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/_schema.yml @@ -0,0 +1,65 @@ +version: 2 + +models: + - name: balancer_v3_sonic_erc4626_token_mapping + meta: + blockchain: sonic + project: balancer + contributors: viniabussafi + config: + tags: ['sonic', 'token', 'mapping'] + description: > + Mapping of ERC4626 tokens on sonic, including aTokens and MetaMorpho tokens, and their corresponding underlying tokens. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - erc4626_token + columns: + - name: blockchain + description: "Blockchain." + - name: erc4626_token + description: "Contract address of the erc4626 token." + - name: erc4626_token_name + description: "Name of the erc4626 token." + - name: erc4626_token_symbol + description: "Symbol of the erc4626 token." + - name: underlying_token + description: "Contract address of the underlying token." + - name: underlying_token_symbol + description: "Symbol of the underlying token." + - name: decimals + description: "Decimal precision of the ERC4626 token." + + - name: balancer_v3_sonic_erc4626_token_prices + meta: + blockchain: sonic + project: balancer + contributors: viniabussafi + config: + tags: ['sonic', 'token', 'prices'] + description: > + Pricing information for ERC4626 tokens on sonic. Prices are derived from the ratio of underlying tokens deposited or withdrawn to shares issued or burned, multiplied by the underlying token price. + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - minute + - wrapped_token + columns: + - name: minute + description: "Timestamp of the event, truncated to the nearest minute." + - name: blockchain + description: "Blockchain." + - name: wrapped_token + description: "Contract address of the wrapped token." + - name: underlying_token + description: "Contract address of the underlying token." + - name: erc4626_token_symbol + description: "Symbol of the erc4626 token." + - name: underlying_token_symbol + description: "Symbol of the underlying token." + - name: decimals + description: "Decimal precision for the token." + - name: median_price + description: "Median price of the static token, computed over the dataset." + - name: next_change + description: "Timestamp of the next expected pricing change or event affecting the price." diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/balancer_v3_sonic_erc4626_token_mapping.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/balancer_v3_sonic_erc4626_token_mapping.sql new file mode 100644 index 00000000000..dcf30383699 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/balancer_v3_sonic_erc4626_token_mapping.sql @@ -0,0 +1,27 @@ +{{ + config( + schema = 'balancer_v3_sonic', + alias = 'erc4626_token_mapping', + materialized = 'table', + file_format = 'delta' + ) +}} + +WITH wrapped_tokens AS( +SELECT + erc4626_token, + erc4626_token_name, + erc4626_token_symbol, + underlying_token, + underlying_token_symbol, + decimals +FROM (VALUES + (0xA28d4dbcC90C849e3249D642f356D85296a12954, 'Wrapped Avalon Avalon SOLVBTCBBN', 'waSonicSOLVBTCBBN', 0xCC0966D8418d412c599A6421b760a847eB169A8c, 'SolvBTC.BBN', 18), + (0xD31E89Ffb929b38bA60D1c7dBeB68c7712EAAb0a, 'Wrapped Avalon Avalon SOLVBTC', 'waSonicSOLVBTC', 0x541FD749419CA806a8bc7da8ac23D346f2dF8B77, 'SolvBTC', 18) + ) AS temp_table (erc4626_token, erc4626_token_name, erc4626_token_symbol, underlying_token, underlying_token_symbol, decimals) +) + +SELECT DISTINCT + 'sonic' AS blockchain, + * +FROM wrapped_tokens \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/balancer_v3_sonic_erc4626_token_prices.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/balancer_v3_sonic_erc4626_token_prices.sql new file mode 100644 index 00000000000..e60c2ffb3eb --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/erc4626_tokens/sonic/balancer_v3_sonic_erc4626_token_prices.sql @@ -0,0 +1,66 @@ +{{ config( + schema = 'balancer_v3_sonic', + alias = 'erc4626_token_prices', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['minute', 'wrapped_token'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.minute')] + ) +}} + + +WITH wrap_unwrap AS( + SELECT + evt_block_time, + wrappedToken, + CAST(depositedUnderlying AS DOUBLE) / CAST(mintedShares AS DOUBLE) AS ratio + FROM {{ source('beethoven_x_v3_sonic', 'Vault_evt_Wrap') }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + + UNION ALL + + SELECT + evt_block_time, + wrappedToken, + CAST(withdrawnUnderlying AS DOUBLE) / CAST(burnedShares AS DOUBLE) AS ratio + FROM {{ source('beethoven_x_v3_sonic', 'Vault_evt_Unwrap') }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + ), + + + price_join AS( + SELECT + w.evt_block_time, + m.underlying_token, + w.wrappedToken, + m.erc4626_token_symbol, + m.underlying_token_symbol, + m.decimals, + ratio * price AS adjusted_price + FROM wrap_unwrap w + JOIN {{ref('balancer_v3_sonic_erc4626_token_mapping')}} m ON m.erc4626_token = w.wrappedToken + JOIN {{ source('prices', 'usd') }} p ON m.underlying_token = p.contract_address + AND p.blockchain = 'sonic' + AND DATE_TRUNC('minute', w.evt_block_time) = DATE_TRUNC('minute', p.minute) + {% if is_incremental() %} + AND {{ incremental_predicate('p.minute') }} + {% endif %} + ) + +SELECT + p.evt_block_time AS minute, + 'sonic' AS blockchain, + wrappedToken AS wrapped_token, + underlying_token, + erc4626_token_symbol, + underlying_token_symbol, + decimals, + APPROX_PERCENTILE(adjusted_price, 0.5) AS median_price, + LEAD(p.evt_block_time, 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrappedToken ORDER BY p.evt_block_time) AS next_change +FROM price_join p +GROUP BY 1, 2, 3, 4, 5, 6, 7 diff --git a/dbt_subprojects/tokens/models/prices/sonic/prices_sonic_tokens.sql b/dbt_subprojects/tokens/models/prices/sonic/prices_sonic_tokens.sql index 35eab529e51..42a4cfb2dd3 100644 --- a/dbt_subprojects/tokens/models/prices/sonic/prices_sonic_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/sonic/prices_sonic_tokens.sql @@ -29,4 +29,6 @@ FROM , ('sceth-sonic-eth', 'scETH', 0x3bce5cb273f0f148010bbea2470e7b5df84c7812, 18) , ('sts-staked-sonic', 'stS', 0xe5da20f15420ad15de0fa650600afc998bbe3955, 18) , ('ag-silver', 'AG', 0x005851f943ee2957b1748957f26319e4f9edebc1, 18) + , ('solvbtc-solv-protocol-solvbtc', 'SOLVBTC', 0x541FD749419CA806a8bc7da8ac23D346f2dF8B77, 18) + , ('solvbtcbbn-solv-protocol-solvbtcbbn', 'SOLVBTCBBN', 0xCC0966D8418d412c599A6421b760a847eB169A8c, 18) ) as temp (token_id, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/sonic/tokens_sonic_erc20.sql b/dbt_subprojects/tokens/models/tokens/sonic/tokens_sonic_erc20.sql index 97f271392dc..d0d0be22177 100644 --- a/dbt_subprojects/tokens/models/tokens/sonic/tokens_sonic_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/sonic/tokens_sonic_erc20.sql @@ -42,4 +42,8 @@ FROM (VALUES , (0x455d5f11Fea33A8fa9D3e285930b478B6bF85265, 'stkscETH', 18) , (0x541FD749419CA806a8bc7da8ac23D346f2dF8B77, 'SolvBTC', 18) , (0xCC0966D8418d412c599A6421b760a847eB169A8c, 'solvBTC.bbn', 18) + , (0xA28d4dbcC90C849e3249D642f356D85296a12954, 'waSonicSOLVBTCBBN', 18) + , (0x773CDA0CADe2A3d86E6D4e30699d40bB95174ff2, 'waSonicSOLVBTC', 18) + , (0x0e65f5a7cb56641e31bc5c9d53388db7ac7eacae, 'atS', 18) + , (0xcf3fe6edfee9c7fdf7d53dc58f4efe66fe110981, 'BUNNY', 18) ) as temp (contract_address, symbol, decimals) diff --git a/sources/aave/gnosis/aave_gnosis_sources.yml b/sources/aave/gnosis/aave_gnosis_sources.yml index f5e9101db8c..57f7a425e62 100644 --- a/sources/aave/gnosis/aave_gnosis_sources.yml +++ b/sources/aave/gnosis/aave_gnosis_sources.yml @@ -5,3 +5,7 @@ sources: description: "Decoded contracts for Aave v3 on Gnosis" tables: - name: AToken_evt_Initialized + + - name: StataTokenV2_evt_Initialized + + - name: StataTokenV2Factory_evt_StataTokenCreated \ No newline at end of file