-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add Solana indexer support #28
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
base: main
Are you sure you want to change the base?
Conversation
- Implemented Solana indexer in `internal/indexer/solana.go` with methods to retrieve block information and transactions. - Created Solana RPC client in `internal/rpc/solana/client.go` to interact with Solana's JSON-RPC API. - Defined Solana API interface in `internal/rpc/solana/api.go` for abstraction. - Added necessary types for Solana RPC responses in `internal/rpc/solana/types.go`. - Updated worker factory in `internal/worker/factory.go` to include Solana indexer initialization.
…ount types in Instruction
…mprove error handling
…roved error handling and performance
internal/indexer/solana.go
Outdated
| ToAddress: r.addr, | ||
| AssetAddress: sender.mint, | ||
| Amount: fmt.Sprintf("%d", amt), | ||
| Type: "token_transfer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should take a look at other chains and reuse similar value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Replaced the custom "token_transfer"/"sol_transfer" strings with the shared tx type used across chains (constant.TxnTypeTransfer) for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we just define new TxType constant
TxTypeTokenTransfer TxType = "token_transfer"
TxTypeNativeTransfer TxType = "native_transfer"
should use either type token transfer or native transfer accordingly
internal/indexer/solana.go
Outdated
| BlockNumber: slot, | ||
| FromAddress: from, | ||
| ToAddress: to, | ||
| AssetAddress: solAssetAddress, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let empty for native sol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed AssetAddress to empty string for native SOL
internal/indexer/solana.go
Outdated
| logger.Info("[SOLANA] extract transfers start", | ||
| "chain", s.chainName, | ||
| "slot", slot, | ||
| "rpc_txs", len(b.Transactions), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this comment, solana will produce noice for the logs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed noisy log [SOLANA] extract transfers start
internal/indexer/solana.go
Outdated
| tokOwnerByAcc := map[string]string{} | ||
| tokMintByAcc := map[string]string{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokMint -> confusing name: tokenOwnerByAcc , tokenMintByAcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed tokOwnerByAcc → tokenOwnerByAcc, tokMintByAcc → tokenMintByAcc
internal/indexer/solana.go
Outdated
| ToAddress: to, | ||
| AssetAddress: solAssetAddress, | ||
| Amount: fmt.Sprintf("%d", lamports), | ||
| Type: constant.TxnTypeTransfer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use new types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use the new transaction types:
constant.TxTypeNativeTransferfor SOL transfersconstant.TxTypeTokenTransferfor SPL token transfers
internal/indexer/solana.go
Outdated
| FromAddress: fromOwner, | ||
| ToAddress: toOwner, | ||
| AssetAddress: mint, | ||
| Amount: fmt.Sprintf("%d", amount), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better to use strconv.FormatUint(amount, 10)?
Method Allocations Relative speed
strconv.FormatUint 1 fastest
fmt.Sprintf 2–4 3–10× slower
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced fmt.Sprintf with strconv.FormatUint for better performance
https://solscan.io/tx/4dc8JLGc2ee2FHXhEfDEXNuG62TZjwvSUGiCwfPnXpiMfCEAcTjg6LXnqEAV9fzbHXaWAiNcNEDrSQMWYmfy9cTv |




This PR adds full indexing support for the Solana blockchain, capable of processing both native SOL and SPL token transfers.
The implementation is built to be resilient and aware of Solana's specific architecture. It correctly handles "skipped slots" as a normal chain event rather than an error, which prevents false positives and ensures the indexer can sync reliably.
To guarantee data integrity, transaction and block processing is robust:
Failed Transactions: The indexer inspects the
meta.errfield for each transaction. If a transaction has failed on-chain, it is skipped, ensuring that only successful transfers are processed and indexed.Reorg Handling & Data Consistency: The indexer's existing reorg detection logic is fully applied to Solana by comparing the
blockhashandpreviousBlockhash. Furthermore, all blocks are fetched withfinalizedcommitment, which provides the strongest guarantee against reorgs and ensures data consistency.