Skip to content
This repository was archived by the owner on Jul 31, 2026. It is now read-only.

feat: support TRC20 token balances for inactive accounts - #190

Merged
ulissesferreira merged 6 commits into
mainfrom
NEB-461-feat-inactive-account-trc20-balances
Feb 13, 2026
Merged

feat: support TRC20 token balances for inactive accounts#190
ulissesferreira merged 6 commits into
mainfrom
NEB-461-feat-inactive-account-trc20-balances

Conversation

@ulissesferreira

@ulissesferreira ulissesferreira commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add support for TRC20 token balances on inactive accounts (accounts that haven't paid the 1 TRX activation fee)
  • Refactor fetchAssetsAndBalancesForAccount to improve code organization and readability

Changes

New TRC20 fallback for inactive accounts:

  • Added getTrc20BalancesByAddress client method that works for inactive accounts (unlike getAccountInfoByAddress which throws)
  • Updated JSDoc on getAccountInfoByAddress and getAccountResources to document their behavior with inactive accounts

Asset extraction refactor:

  • Introduced NormalizedAccountData type to provide a consistent data shape for both active and inactive accounts
  • Added #buildAccountData to normalize API responses, centralizing active/inactive branching logic
  • Added #extractAssets coordinator that calls all individual extractors uniformly
  • Simplified extract function signatures to accept direct values instead of container objects
  • Added #enrichAssetsWithMetadata to encapsulate metadata enrichment logic
  • Added #getPriceableAssetTypes helper for filtering assets that can be priced
  • Removed #createZeroBalanceNativeAsset (no longer needed after normalization)

@ulissesferreira
ulissesferreira requested a review from a team as a code owner February 3, 2026 14:21
@ulissesferreira
ulissesferreira marked this pull request as draft February 3, 2026 14:24
@ulissesferreira ulissesferreira changed the title feat(NEB-461): support TRC20 token balances for inactive accounts feat: support TRC20 token balances for inactive accounts Feb 3, 2026
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch 2 times, most recently from beea8e5 to 82f12a3 Compare February 4, 2026 12:51
@ulissesferreira
ulissesferreira marked this pull request as ready for review February 4, 2026 12:58
Comment thread packages/snap/src/services/assets/AssetsService.test.ts Outdated
Comment thread packages/snap/src/services/assets/AssetsService.test.ts Outdated
Comment thread packages/snap/src/services/assets/AssetsService.test.ts Outdated
Comment thread packages/snap/src/services/assets/AssetsService.test.ts Outdated
Comment thread packages/snap/src/services/assets/AssetsService.test.ts Outdated
Comment thread packages/snap/src/services/assets/AssetsService.test.ts Outdated
Comment thread packages/snap/src/clients/trongrid/TrongridApiClient.test.ts Outdated
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch 4 times, most recently from 38156a6 to cd1e61d Compare February 4, 2026 23:31
});

describe('extreme values (original bug scenarios)', () => {
describe('values out of `Number` 64-bit size', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nit: @mikesposito, didn't forget about it

@ulissesferreira ulissesferreira Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Particularly happy with the structure here. I am going for a method that orchestrates the whole thing, doing the data fetching at first, data parsing, enriching and finally returning. The fallbacks are handled right at the start and everything else is shared. Took some iterations to get here, feel free to suggest even more improvements

* Get TRC20 token balances for an account address.
* This endpoint works for inactive accounts that haven't been activated yet.
*
* @see https://developers.tron.network/reference/get-trc20-token-holder-balances

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the key endpoint missing for us to be able to offer this feature

Comment thread packages/snap/src/services/assets/AssetsService.test.ts
Comment thread packages/snap/src/clients/trongrid/TrongridApiClient.test.ts Outdated
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch 3 times, most recently from a3724b5 to 5f60ff6 Compare February 9, 2026 17:42
Comment thread packages/snap/src/clients/trongrid/TrongridApiClient.test.ts Outdated
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch from 5f60ff6 to 688d3f9 Compare February 11, 2026 15:10
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch 2 times, most recently from 0a02e10 to 5361765 Compare February 12, 2026 12:22
Add fallback TRC20 balance fetching for inactive Tron accounts using the
`/v1/accounts/{address}/trc20/balance` endpoint when the main account
info endpoint returns no data (inactive accounts that haven't paid the
1 TRX activation fee).

- Add `getTrc20BalancesByAddress()` method to TrongridApiClient
- Implement fallback logic in AssetsService for inactive accounts
- Add helper methods for zero-balance native assets and TRC20 extraction
- Add comprehensive unit tests for new functionality
Use InMemoryCache in TrongridApiClient tests and drop redundant section comments in AssetsService.
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch from 5361765 to f21970f Compare February 12, 2026 15:08
@ulissesferreira
ulissesferreira force-pushed the NEB-461-feat-inactive-account-trc20-balances branch from f21970f to 98c7dd6 Compare February 12, 2026 15:09

@mikesposito mikesposito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ulissesferreira
ulissesferreira merged commit 616445e into main Feb 13, 2026
11 checks passed
@ulissesferreira
ulissesferreira deleted the NEB-461-feat-inactive-account-trc20-balances branch February 13, 2026 09:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants