Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init sonic erc4626 token mapping #7538

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -32,7 +32,7 @@ models:

- name: balancer_v3_erc4626_token_prices
meta:
blockchain: ethereum, gnosis
blockchain: ethereum, gnosis, sonic
project: balancer
contributors: viniabussafi
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
Original file line number Diff line number Diff line change
@@ -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."
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions sources/aave/gnosis/aave_gnosis_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading