Introduction
The one thing that wasn’t great about Solana until recently is the indexing situation. Subsquid’s SDK now provides decentralized indexing tools for developers and analysts working with Solana transaction data.
Solana vs Ethereum: Key Differences
Ethereum Structure
Ethereum transactions follow a straightforward model with essential fields:
- Sender and receiver addresses
- Digital signatures confirming authorization
- Nonce indicating transaction order
- ETH transfer amounts
- Optional input data
- Gas-related parameters
Most Ethereum transactions interact with contract accounts written in Solidity, which interpret input data according to the Ethereum Application Binary Interface (ABI).
Solana Structure
Solana’s architecture is more complex, supporting multiple instructions within a single transaction — comparable to a series of internal calls within one overarching operation. A Solana transaction includes:
- Array of signatures for authentication
- Instructions component detailing operations to perform
- Program specification for each instruction
- Accounts involved in the operation
- Operation data
- Inner instructions (Cross Program Invocations, or CPIs)
Real-World Application Example
Comparing decentralized finance platforms: Uniswap on Ethereum versus Orca on Solana. While Uniswap manages pairs through individual addresses, Orca pairs are identified by program IDs. Data organization differs significantly; Ethereum’s architecture simplifies accessing swap amounts and token addresses, whereas Solana requires decoding this information from the transaction’s inner instructions.
Ethereum Transaction Components
- from: Sender’s address (externally owned account)
- to: Recipient address
- signature: Authorization confirmation generated by private key
- nonce: Sequential counter indicating transaction number
- value: ETH amount transferred (in WEI)
- input data: Optional arbitrary data field
- gasLimit: Maximum gas units consumable
- maxPriorityFeePerGas: Maximum gas price as validator tip
- maxFeePerGas: Maximum fee per gas unit willing to be paid
Solana Instruction Components
- Executing Account: Program ID using base58 encoding
- Account Arguments: Unlabeled array of all involved accounts
- Data: Base58-encoded field specifying function calls and parameters
- Inner Instructions: Program-to-program calls (CPIs) in sequential format
Querying and Indexing
Subsquid’s Solana processor enables complex queries like instructions[1].inner_instructions[2].data, providing granular examination of program interactions within transactions.
Indexing Orca Whirlpool AMM
The tutorial demonstrates setting up a data source:
const dataSource = new DataSourceBuilder()
.setGateway('<https://v2.archive.subsquid.io/network/solana-mainnet>')
.setRpc(process.env.SOLANA_NODE == null ? undefined : {
client: new SolanaRpcClient({
url: process.env.SOLANA_NODE,
}),
strideConcurrency: 10
})
.setBlockRange({from: 240_000_000})
.setFields({
block: { timestamp: true },
transaction: { signatures: true },
instruction: {
programId: true,
accounts: true,
data: true
},
tokenBalance: {
preAmount: true,
postAmount: true,
preOwner: true,
postOwner: true
}
})
.addInstruction({
where: {
programId: [whirlpool.programId],
d8: [whirlpool.swap.d8],
isCommitted: true
},
include: {
innerInstructions: true,
transaction: true,
transactionTokenBalances: true,
}
}).build()
Data Extraction Process
The indexing workflow involves:
- Iterating through blocks and instructions
- Identifying transactions matching the Whirlpool program ID
- Creating Exchange entities containing transaction ID, slot, and timestamp
- Decoding inner instructions to extract transfer details
- Retrieving associated token balances
- Verifying instruction signatures
- Extracting source and destination mint information
- Unpacking remaining data from balances and saving the exchange
Compared to Ethereum there is a lot more nesting of data going on due to Solana’s complex data organisation and execution flow.
Conclusion
While Solana’s architecture differs significantly from Ethereum, the Subsquid SDK provides a familiar developer experience. Solana, with its unique approach of allowing multiple contract calls in a single transaction, offers a treasure trove of data and flexibility that stands apart from the familiar territory of Ethereum’s EVM.
Indexing Orca Whirlpool exemplifies how Subsquid’s toolkit simplifies working with Solana’s complex, data-intensive structure, ensuring transparency and accessibility in decentralized finance across networks.
Additional Resources:
- Test project available on GitHub
- Subsquid Website