Skip to content

fix(sdk-coin-trx): guard against missing trc20 field in account response#9277

Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
spt-101/fix-trx-token-consolidation-missing-trc20
Draft

fix(sdk-coin-trx): guard against missing trc20 field in account response#9277
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
spt-101/fix-trx-token-consolidation-missing-trc20

Conversation

@bitgo-ai-agent-dev

Copy link
Copy Markdown

What

  • Mark trc20 as optional in the AccountInfo interface to reflect the real TRON node API contract
  • Guard all three recovery code paths (recover(), recoverTss(), recoverConsolidations()) against a missing trc20 field using ?? [] nullish coalescing
  • Add unit tests for all three paths verifying graceful handling when trc20 is absent from the account response

Why

  • BitOasis reported that USDT:TRX balance consolidation was failing with a TypeError crash
  • The TRON node API omits the trc20 field entirely from account info responses for wallets that have never interacted with TRC20 tokens (e.g. pure TRX receive addresses used as intermediary accounts)
  • Iterating over an undefined field caused an unhandled exception, preventing any consolidation or token recovery from completing when any scanned address had this property absent

Test plan

  • New test: should throw if trc20 field absent and token recovery requested (base address) — confirms base-address recovery throws a clear "token not found" error rather than a TypeError
  • New test: should skip token consolidation when trc20 field absent from account response — confirms consolidation silently skips addresses without TRC20 data
  • New test: should throw if trc20 field absent for TSS wallet token recovery — confirms TSS wallet recovery throws a clear "token not found" error
  • All existing tests continue to pass (pre-existing failures in other tests are unrelated to this change and exist on master)

Ticket: SPT-101

The TRON node API omits the `trc20` field entirely from account info
responses for accounts that have never interacted with TRC20 tokens.
Three recovery paths iterated over `account.data[0].trc20` without
first checking whether the field exists, causing a TypeError crash
("Cannot read properties of undefined (reading Symbol.iterator)")
whenever consolidation or recovery was attempted and any scanned
receive address had TRX balance but no prior TRC20 history.

Fix: use the `?? []` nullish coalescing fallback when iterating in
`recover()`, `recoverTss()`, and `recoverConsolidations()`. Also
mark the `trc20` field optional in `AccountInfo` to reflect the real
API contract.

Add unit tests for all three code paths that confirm graceful handling
when the `trc20` field is absent (the base-address recovery and TSS
recovery throw a clear "token not found" error, and consolidation
skips the address instead of crashing).

Ticket: SPT-101
Session-Id: e2414be7-1b86-4412-b43c-7267b56dac1d
Task-Id: 1123cac4-3d06-4115-8039-d9aea9e761aa
@linear-code

linear-code Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

SPT-101

@bitgo-ai-agent-dev
bitgo-ai-agent-dev Bot force-pushed the spt-101/fix-trx-token-consolidation-missing-trc20 branch from 269a7b5 to eb57a0f Compare July 16, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants