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

Map tokens on poolbalancechanged event #154

Closed
viniabussafi opened this issue Oct 15, 2024 · 1 comment
Closed

Map tokens on poolbalancechanged event #154

viniabussafi opened this issue Oct 15, 2024 · 1 comment
Assignees

Comments

@viniabussafi
Copy link
Member

viniabussafi commented Oct 15, 2024

with the tokens field being removed from the event, we will have to map them based on the order they were registered on the vault

@viniabussafi viniabussafi self-assigned this Oct 15, 2024
@viniabussafi
Copy link
Member Author

balances_changes AS (
WITH token_data AS (
SELECT
pool,
ARRAY_AGG(CAST(json_extract_scalar(token, '$.token') AS varbinary) ORDER BY token_index) AS tokens -- Cast to varbinary
FROM (
SELECT
pool,
tokenConfig,
SEQUENCE(1, CARDINALITY(tokenConfig)) AS token_index_array
FROM
balancer_testnet_sepolia.Vault_evt_PoolRegistered
) AS pool_data
CROSS JOIN UNNEST(tokenConfig, token_index_array) AS t(token, token_index)
GROUP BY 1
)
SELECT
date_trunc('day', evt_block_time) AS day,
contract_address AS vault_address,
pb.pool AS pool_address,
t.token,
d.delta
FROM
balancer_testnet_sepolia.Vault_evt_PoolBalanceChanged pb
JOIN token_data td ON pb.pool = td.pool
CROSS JOIN UNNEST(td.tokens) WITH ORDINALITY AS t(token, i)
CROSS JOIN UNNEST(pb.deltas) WITH ORDINALITY AS d(delta, i)
WHERE t.i = d.i
ORDER BY 1, 2, 3
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant