Skip to content

feat(rpc): impl getTokenAccountBalance RPC #1237

Draft
prestonsn wants to merge 2 commits intoprestonsn/impl-get-account-info-for-db-twofrom
prestonsn/impl-get-token-account-balance
Draft

feat(rpc): impl getTokenAccountBalance RPC #1237
prestonsn wants to merge 2 commits intoprestonsn/impl-get-account-info-for-db-twofrom
prestonsn/impl-get-token-account-balance

Conversation

@prestonsn
Copy link
Contributor

Implements https://solana.com/docs/rpc/http/gettokenaccountbalance

  • Add getTokenAccountBalance endpoint that returns token balance with
  • UI amount formatting. Handles SPL Token and Token-2022 accounts,
  • including interest-bearing and scaled UI amount extension configs.

Sample response from testing (8KMd8WMacjWd9Md3rZjy7yxx7v7zyZMye4XdrXdV3rHN) :

{
  "context": {
    "slot": 389457101,
    "apiVersion": "0.2.0"
  },
  "value": {
    "uiAmount": 600013911.6102316,
    "decimals": 9,
    "amount": "600013911610231717",
    "uiAmountString": "600013911.610231717"
  }
}

Implement the getAccountInfo RPC method with full support for all Solana
account encodings: base58, base64, base64+zstd, and jsonParsed.
- Add AccountHookContext with getAccountInfo method for reading account data
- Support dataSlice parameter for partial account reads
- Implement streaming zstd compression for base64+zstd encoding
- Fall back to base64 encoding when no jsonParsed parser is available
Add comprehensive account parsing for the following program types:
- **Vote accounts**: Parse vote state with authorized voters, prior voters,
  epoch credits, and last timestamp
- **Stake accounts**: Parse delegation info, stake activation, and lockup
- **Nonce accounts**: Parse authority, blockhash, and fee calculator
- **Address Lookup Tables**: Parse lookup table state with addresses
- **BPF Upgradeable Loader**: Parse program, programData, and buffer accounts
- **Sysvars**: Parse clock, rent, epochSchedule, slotHistory, slotHashes,
  stakeHistory, epochRewards, fees, recentBlockhashes, and lastRestartSlot
- **Config accounts**: Parse validator info and stake config
- **SPL Token & Token-2022**: Full token account, mint, and multisig parsing
  with extension support (transfer fees, interest-bearing, metadata, etc.)
- Parse all token extensions including TransferFeeConfig, InterestBearingConfig,
  TokenMetadata, ConfidentialTransferMint, PermanentDelegate, and more
- Support interest-bearing token amount calculations with compound interest
- Support scaled UI amounts with multiplier switching
- Parse TokenMetadata additional_metadata key-value pairs
- Move AccountEncoding enum to common module for reuse
- Add SPL_TOKEN_PROGRAM_ID and SPL_TOKEN_2022_PROGRAM_ID to runtime/ids.zig
- Move MAX_ENTRIES constant into SlotHistory struct
- Fix SlotTracker to avoid use-after-free issues with processed/confirmed counters
- Add getTokenAccountBalance endpoint that returns token balance with
- UI amount formatting. Handles SPL Token and Token-2022 accounts,
- including interest-bearing and scaled UI amount extension configs.
@prestonsn prestonsn requested review from dnut and ultd as code owners February 19, 2026 04:03
@prestonsn prestonsn requested a review from yewman as a code owner February 19, 2026 04:03
@github-project-automation github-project-automation bot moved this to 🏗 In progress in Sig Feb 19, 2026
@prestonsn prestonsn self-assigned this Feb 19, 2026
@prestonsn prestonsn marked this pull request as draft February 19, 2026 04:04
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/rpc/account_decoder/lib.zig 73.82% <ø> (ø)
src/rpc/account_decoder/parse_token.zig 92.16% <100.00%> (+1.56%) ⬆️
src/rpc/methods.zig 78.68% <ø> (-1.32%) ⬇️
src/rpc/test_serialize.zig 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@prestonsn prestonsn force-pushed the prestonsn/impl-get-account-info-for-db-two branch 4 times, most recently from b67e6b1 to a0a5842 Compare February 26, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

1 participant