-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0b3045
commit 4b334b5
Showing
3 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
222 changes: 222 additions & 0 deletions
222
...abels/addresses/__single_category_labels__/beethoven_x/labels_beethoven_x_pools_sonic.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
{{config( | ||
alias = 'beethoven_x_pools_fantom', | ||
post_hook = '{{ expose_spells(\'["fantom"]\', | ||
"sector", | ||
"labels", | ||
\'["viniabussafi"]\') }}' | ||
)}} | ||
|
||
WITH v2_pools AS( | ||
WITH pools AS ( | ||
SELECT | ||
pool_id, | ||
zip.tokens AS token_address, | ||
zip.weights / pow(10, 18) AS normalized_weight, | ||
symbol, | ||
pool_type, | ||
pool_name | ||
FROM ( | ||
SELECT | ||
c.poolId AS pool_id, | ||
t.tokens, | ||
w.weights, | ||
cc.symbol, | ||
'weighted' AS pool_type, | ||
cc.name AS pool_name | ||
FROM {{ source('beethoven_x_v2_sonic', 'Vault_evt_PoolRegistered') }} c | ||
INNER JOIN {{ source('beethoven_x_v2_sonic', 'WeightedPoolFactory_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) WITH ORDINALITY t(tokens, pos) | ||
CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) | ||
WHERE t.pos = w.pos | ||
) zip | ||
|
||
|
||
UNION ALL | ||
|
||
SELECT | ||
c.poolId AS pool_id, | ||
t.tokens AS token_address, | ||
0 AS normalized_weight, | ||
cc.symbol, | ||
'stable' AS pool_type, | ||
cc.name AS pool_name | ||
FROM {{ source('beethoven_x_v2_sonic', 'Vault_evt_PoolRegistered') }} c | ||
INNER JOIN {{ source('beethoven_x_v2_sonic', 'ComposableStablePoolFactory_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 ( | ||
SELECT | ||
pool_id, | ||
coalesce(t.symbol, '?') AS token_symbol, | ||
normalized_weight, | ||
p.symbol AS pool_symbol, | ||
p.pool_type, | ||
p.pool_name | ||
FROM pools p | ||
LEFT JOIN {{ source('tokens', 'erc20') }} t ON p.token_address = t.contract_address | ||
AND t.blockchain = 'sonic' | ||
) | ||
|
||
SELECT | ||
'fantom' AS blockchain, | ||
bytearray_substring(pool_id, 1, 20) AS address, | ||
CASE WHEN pool_type IN ('stable') | ||
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), '/'))) | ||
END AS name, | ||
pool_name AS poolname, | ||
pool_type, | ||
'2' AS version, | ||
'beethoven_x_v2_pool' AS category, | ||
'beethoven_x' AS contributor, | ||
'query' AS source, | ||
TIMESTAMP'2024-12-15 00:00' AS created_at, | ||
now() AS updated_at, | ||
'beethoven_x_pools_fantom' AS model_name, | ||
'identifier' AS label_type | ||
FROM ( | ||
SELECT | ||
s1.pool_id, | ||
token_symbol, | ||
pool_symbol, | ||
cast(100 * normalized_weight AS integer) AS norm_weight, | ||
pool_type, | ||
pool_name | ||
FROM settings s1 | ||
GROUP BY s1.pool_id, token_symbol, pool_symbol, normalized_weight, pool_type, pool_name | ||
) s | ||
GROUP BY pool_id, pool_symbol, pool_type, pool_name | ||
ORDER BY 1) | ||
|
||
v3_pools AS( | ||
WITH token_data AS ( | ||
SELECT | ||
pool, | ||
ARRAY_AGG(FROM_HEX(json_extract_scalar(token, '$.token')) ORDER BY token_index) AS tokens | ||
FROM ( | ||
SELECT | ||
pool, | ||
tokenConfig, | ||
SEQUENCE(1, CARDINALITY(tokenConfig)) AS token_index_array | ||
FROM {{ source('beethoven_x_v3_sonic', 'Vault_evt_PoolRegistered') }} | ||
) AS pool_data | ||
CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index) | ||
GROUP BY 1 | ||
), | ||
|
||
pools AS ( | ||
SELECT | ||
pool_id, | ||
zip.tokens AS token_address, | ||
zip.weights / POWER(10, 18) AS normalized_weight, | ||
symbol, | ||
pool_type | ||
FROM ( | ||
SELECT | ||
c.pool AS pool_id, | ||
t.tokens, | ||
w.weights, | ||
cc.symbol, | ||
'weighted' AS pool_type | ||
FROM token_data c | ||
INNER JOIN {{ source('beethoven_x_v3_sonic', 'WeightedPoolFactory_call_create') }} cc | ||
ON c.pool = cc.output_pool | ||
CROSS JOIN UNNEST(c.tokens) WITH ORDINALITY t(tokens, pos) | ||
CROSS JOIN UNNEST(cc.normalizedWeights) WITH ORDINALITY w(weights, pos) | ||
WHERE t.pos = w.pos | ||
|
||
UNION ALL | ||
|
||
SELECT | ||
c.pool AS pool_id, | ||
t.tokens, | ||
0 AS weights, | ||
cc.symbol, | ||
'stable' AS pool_type | ||
FROM token_data c | ||
INNER JOIN {{ source('beethoven_x_v3_sonic', 'StablePoolFactory_call_create') }} cc | ||
ON c.pool = cc.output_pool | ||
CROSS JOIN UNNEST(c.tokens) AS t(tokens) | ||
) zip | ||
), | ||
|
||
settings AS ( | ||
SELECT | ||
pool_id, | ||
coalesce(t.symbol, '?') AS token_symbol, | ||
normalized_weight, | ||
p.symbol AS pool_symbol, | ||
p.pool_type | ||
FROM pools p | ||
LEFT JOIN {{ source('tokens', 'erc20') }} t ON p.token_address = t.contract_address | ||
AND t.blockchain = 'sonic' | ||
) | ||
|
||
SELECT | ||
'sonic' AS blockchain, | ||
bytearray_substring(pool_id, 1, 20) AS address, | ||
CASE WHEN pool_type IN ('stable') | ||
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), '/'))) | ||
END AS name, | ||
pool_type, | ||
'3' AS version, | ||
'beethoven_x_v3_pool' AS category, | ||
'beethoven_x' AS contributor, | ||
'query' AS source, | ||
TIMESTAMP'2024-12-15 00:00' AS created_at, | ||
now() AS updated_at, | ||
'balancer_v3_pools_sonic' AS model_name, | ||
'identifier' AS label_type | ||
FROM ( | ||
SELECT | ||
s1.pool_id, | ||
token_symbol, | ||
pool_symbol, | ||
cast(100 * normalized_weight AS integer) AS norm_weight, | ||
pool_type | ||
FROM settings s1 | ||
GROUP BY s1.pool_id, token_symbol, pool_symbol, normalized_weight, pool_type | ||
) s | ||
GROUP BY pool_id, pool_symbol, pool_type | ||
ORDER BY 1 | ||
) | ||
|
||
SELECT | ||
blockchain, | ||
address, | ||
name, | ||
pool_type, | ||
version, | ||
category, | ||
contributor, | ||
source, | ||
created_at, | ||
updated_at, | ||
model_name, | ||
label_type | ||
FROM v2_pools | ||
|
||
UNION | ||
|
||
SELECT | ||
blockchain, | ||
address, | ||
name, | ||
pool_type, | ||
version, | ||
category, | ||
contributor, | ||
source, | ||
created_at, | ||
updated_at, | ||
model_name, | ||
label_type | ||
FROM v3_pools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: beethoven_x_v2_sonic | ||
description: "sonic decoded tables related to beethoven x's contracts" | ||
tables: | ||
- name: Vault_evt_Swap | ||
- name: Vault_evt_PoolRegistered | ||
- name: WeightedPoolFactory_call_create | ||
- name: Vault_evt_PoolBalanceChanged | ||
- name: Vault_evt_PoolBalanceManaged | ||
- name: ComposableStablePoolFactory_call_create | ||
|
||
- name: beethoven_x_v3_sonic | ||
description: > | ||
Decoded tables related to Beethoven X, an automated portfolio manager and trading platform, on Sonic. | ||
tables: | ||
- name: Vault_evt_PoolRegistered | ||
- name: WeightedPoolFactory_evt_PoolCreated | ||
- name: WeightedPoolFactory_call_create | ||
- name: Vault_evt_LiquidityAdded | ||
- name: Vault_evt_LiquidityRemoved | ||
- name: StablePoolFactory_evt_PoolCreated | ||
- name: StablePoolFactory_call_create | ||
- name: Vault_evt_Swap | ||
- name: ProtocolFeeController_evt_ProtocolSwapFeeCollected | ||
- name: ProtocolFeeController_evt_ProtocolYieldFeeCollected | ||
- name: Vault_evt_Wrap | ||
- name: Vault_evt_Unwrap | ||
- name: Vault_evt_LiquidityAddedToBuffer | ||
- name: Vault_evt_LiquidityRemovedFromBuffer | ||
- name: Vault_evt_SwapFeePercentageChanged |