-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[BUG] token_mint_address in tokens_solana.transfers is different on solscan #6690
Comments
here are two specific transactions with a different dune token address than what solscan shows: Transaction 1
select *
from tokens_solana.transfers t
where t.block_date = cast('2024-07-21' as date) -- date filter to improve performance
and t.tx_id = '2tjLmmksKz636jKacMoNnGKTvUdBCSWsUtzuswGskXae8PNa9Gr1Qb2XZdRtK5ne4BR7oB8mryV2RN6t8bqiULCP' Transaction 2
select *
from tokens_solana.transfers t
where t.block_date = cast('2024-04-15' as date) -- date filter to improve performance
and t.tx_id = '47JfrTa9NaPQJmzQM1sJ8JcUbsSDAycjuABV1GxT3bZNQesQSNamtEWWyKFYt81SvEqP9gkvgEyw1KNGaxHsteLk' Query to retrieve negative balanceshere is a dune query showing all negative balances for the MNDE solana token, you can remove the token filter in the first CTE to assess all tokens -- filtering to only a set of tokens to improve performance
-- you can remove this to see the results for all tokens
with transfers_filtered as (
select *
from tokens_solana.transfers t
where t.token_mint_address in (
'MNDEFzGvMt87ueuHvVU9VcTqsAP5b3fTGPsHuuPA5ey'
)
),
-- aggregate wallet-level transfers by counting transfers in as positive and transfers out as negative
wallet_transfers as (
select 'solana' as chain
,t.block_time
,t.from_token_account as wallet_address
,-t.amount as transfer_amount
,token_mint_address
from transfers_filtered t
union all
select 'solana' as chain
,t.block_time
,t.to_token_account as wallet_address
,t.amount as transfer_amount
,token_mint_address
from transfers_filtered t
),
-- calculate wallet balances by summing net transfers over time for each wallet
wallet_balances as (
select chain
,block_time
,wallet_address
,token_mint_address
,transfer_amount
,sum(transfer_amount) over (partition by chain,wallet_address,token_mint_address order by block_time asc) as balance
from wallet_transfers
)
select chain
,token_mint_address
,wallet_address
,min(balance) as lowest_balance
from wallet_balances
-- filter to balances below -1 rather than 0 to filter any rounding errors
where balance < -1
group by 1,2,3
order by 1,2,4 desc |
closing issue due to inactivity. if still relevant, and proposed fix is available, feel free to reopen an issue as needed. |
these transactions still show the wrong mint address in dune, meaning that dune data doesn't match the actual blockchain. we are already in the middle of switching our infrastructure to use the solana blockchain in google public datasets rather than the dune API because the incorrect dune data is breaking dbt tests that check for negative token balances. |
happy to reopen the issue, was just doing a mass cleanup. it's important to note that
we would need to identify which of these types of transfers the troubled tx's come from. once narrowed down, we can dig into the code which compiles those curated transfers datasets. can either of you help identify the next steps to a solution? |
definitely empathize with the need for mass ticket cleanup. I'll try to take a look at the underlying tables and see if I can identify the source of the issue, thanks for linking the definition. |
it's quite the lineage of spells, so plz do ask questions as you navigate around it 🙏 |
ok as a starting place I can confirm that the raw query to show transaction details for example 1 above, but with the correct mint address: WITH pre_balances AS (
SELECT
t.signature,
t.block_date,
pre.account,
pre.mint,
pre.owner,
pre.amount
FROM solana.transactions t,
UNNEST(pre_token_balances) AS pre(account, mint, owner, amount)
WHERE block_date = cast('2024-07-21' as date)
AND signature = '2tjLmmksKz636jKacMoNnGKTvUdBCSWsUtzuswGskXae8PNa9Gr1Qb2XZdRtK5ne4BR7oB8mryV2RN6t8bqiULCP'
),
post_balances AS (
SELECT
t.signature,
post.account,
post.mint,
post.owner,
post.amount
FROM solana.transactions t,
UNNEST(post_token_balances) AS post(account, mint, owner, amount)
WHERE block_date = cast('2024-07-21' as date)
AND signature = '2tjLmmksKz636jKacMoNnGKTvUdBCSWsUtzuswGskXae8PNa9Gr1Qb2XZdRtK5ne4BR7oB8mryV2RN6t8bqiULCP'
)
SELECT
pre.block_date,
pre.signature,
pre.account,
pre.mint,
pre.owner,
pre.amount as pre_amount,
post.amount as post_amount,
post.amount - pre.amount as transfer
FROM pre_balances pre
FULL OUTER JOIN post_balances post
ON pre.signature = post.signature
AND pre.account = post.account
AND pre.mint = post.mint |
the underlying table select *
from tokens_solana.spl_transfers_call_transfer_2024_q3 t
WHERE block_date = cast('2024-07-21' as date)
and t.tx_id = '2tjLmmksKz636jKacMoNnGKTvUdBCSWsUtzuswGskXae8PNa9Gr1Qb2XZdRtK5ne4BR7oB8mryV2RN6t8bqiULCP'
limit 100 |
Summary of root causethe bug is caused by solana owner-account pairs that have transactions with multiple SPL tokens, while the logic in the solana_utils.token_accounts table only allows for a single SPL token to be associated with a pair. the solana blockchain appears to allow an owner-account pairing to be used for multiple SPL tokens as long as the prior token's total balance has been sent and is thus reset to 0. Walkthrough of example transaction with bugthe record for the account using the dune query below, we can see that account Correct treatmentrather than selecting the first token_mint_address by date (i.e. Dune query showing interactions with 5 tokens by the owner-account pairselect address,
token_balance_owner,
block_time,
token_mint_address,
pre_token_balance,
post_token_balance,
token_balance_change
from solana.account_activity
where address = 'YgiU6QrKidVFS6PhwoeTeHZXiSc8Av2UykCk7umyddo'
and tx_success = true
order by block_time Blockchain data verifying interactions with 5 tokens by this owner-account pairhere is a link to the blockchain transaction data showing the Proposed fixmy initial suggestion would be to modify |
thank you for the detailed breakdown. i have raised this as a bug in our backlog to prioritize, in case no one else proactively opens a PR to try to help resolve. |
@jeff-dude can you link me to the definition of |
that's a decoded table, so a source built prior to being used in spellbook. |
if that's the case then I think the fix I proposed with modified this modified token_accounts table would shift from a one-to-one to a one-to-many relationship between owner-address pairs and token_mint_address, which is spooky both because changes would be breaking for current queries and because existing queries that use either if you think it makes sense for me to draft a PR based on either proposal I can try to do that this or next week, but it might make more sense to wait until a PM or someone else has time to review all this info. let me know if you think drafting a PR would help move things along quicker though. |
our team likely won't have time to prioritize until at the best next week, so if you can find time to open a PR, that would help expedite for sure. we could leverage the PR as a visual / example to help review with the team internally and look for approval. i agree that |
Description
token_mint_address in tokens_solana.transfers is different on solscan .
some examples in the discord thread https://discord.com/channels/757637422384283659/1281025587405787177/1282371830186774651
Current behavior
token_mint_address showing a different address
Expected behavior
addresses should match with solana explorers
Impacted model(s)
https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/solana/models/tokens/solana/tokens_solana_transfers.sql#L66
Possible solution
havnt thought of a solution yet, just creating this issue to track
The text was updated successfully, but these errors were encountered: