Skip to content

fix: ton tx history parsing#11727

Merged
gomesalexandre merged 7 commits intodevelopfrom
auto-claude/008-the-ton-implementation-isn-t-parsing-txs-properly-
Feb 9, 2026
Merged

fix: ton tx history parsing#11727
gomesalexandre merged 7 commits intodevelopfrom
auto-claude/008-the-ton-implementation-isn-t-parsing-txs-properly-

Conversation

@NeOMakinG
Copy link
Collaborator

@NeOMakinG NeOMakinG commented Jan 19, 2026

Description

Fixes the TON tx parsing upserted into history, which wasn't working at all previously

Issue (if applicable)

closes #

Risk

High Risk PRs Require 2 approvals

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

Testing

  • Do a TON to a jettons coin swap
  • Do a jettons coin swap to TON
  • Notice all the TXs are upserted in the history

Engineering

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

image image

Summary by CodeRabbit

  • New Features
    • Implemented transaction history retrieval for TON blockchain
    • Added jetton (TON token) transfer tracking and support
    • Enhanced address normalization for improved transaction clarity
    • Added pagination support for efficient transaction history queries

✏️ Tip: You can customize this high-level summary in your review settings.

Minimoi and others added 4 commits January 18, 2026 21:00
…unknown

- Changed parseTx parameter from `msgHash: string` to `txHashOrTx: unknown`
- Added type checking to convert unknown to string for use
- Follows the pattern established in TronChainAdapter.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…te parse

- Add TonTx and TonTxMessage types to packages/chain-adapters/src/ton/types.ts
- Create private parse() helper method in TonChainAdapter.ts following
  Tron and SecondClassEvmAdapter patterns
- parse() method handles:
  - Transaction status determination (aborted/success)
  - Transfer direction detection (send/receive)
  - Building transfers array from in_msg and out_msgs
  - Returning properly structured Transaction object
- Update parseTx() to call parse() after fetching transaction data
- Improve error handling when transaction is not found

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…dle TON token transfers

- Add parseJettonTransfers method to fetch and parse Jetton transfers from Toncenter v3 API
- Update parseTx to include Jetton transfers in transaction data
- Use address_book to convert raw addresses to user-friendly format
- Support both send and receive transfer types for Jettons

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…e import

- Removed unused TonTxMessage type import from TonChainAdapter.ts
- Lint check passes
- Package build succeeds (all 8 packages compile)
- Full type-check requires Java for OpenAPI generator (pre-existing infrastructure requirement)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

This PR implements transaction history retrieval for the TON chain adapter, including batching and pagination support. It adds jetton (TON token) transfer parsing and address normalization, refactors the public parseTx method to private, and introduces new private helper functions for consolidated transfer extraction and token transfer parsing.

Changes

Cohort / File(s) Summary
Type Definitions
packages/chain-adapters/src/ton/types.ts
Added new public types TonTxMessage (with optional source, destination, value fields) and TonTx (containing account, hash, lt, now, total_fees, optional in_msg and out_msgs array).
Transaction History & Jetton Integration
packages/chain-adapters/src/ton/TonChainAdapter.ts
Implemented getTxHistory() method with batching via requestQueue and pagination support (cursor, pageSize). Added parseJettonTransfers() helper to extract token transfers. Introduced parse() function to consolidate transfer extraction from in_msg/out_msgs and determine transaction status. Refactored parseTx() from public to private and expanded it to support transaction hash resolution and address book normalization. Integrated jetton transfers into transaction results.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant getTxHistory
    participant requestQueue
    participant parseTx
    participant parseJettonTransfers
    participant addressBook

    Client->>getTxHistory: getTxHistory(input)
    activate getTxHistory
    getTxHistory->>getTxHistory: Initialize cursor & pagination
    loop Until no more results
        getTxHistory->>requestQueue: Queue fetch request
        requestQueue->>requestQueue: Fetch transactions (cursor, pageSize)
        requestQueue-->>getTxHistory: txs array
        loop For each transaction
            getTxHistory->>parseTx: parseTx(tx, pubkey)
            activate parseTx
            parseTx->>parse: parse(tx, pubkey, txid)
            activate parse
            parse->>addressBook: Normalize in_msg/out_msgs
            addressBook-->>parse: Resolved addresses
            parse-->>parseTx: Transaction with transfers
            deactivate parse
            parseTx->>parseJettonTransfers: parseJettonTransfers(txHash, pubkey)
            activate parseJettonTransfers
            parseJettonTransfers-->>parseTx: Jetton transfers
            deactivate parseJettonTransfers
            parseTx-->>getTxHistory: Combined transaction
            deactivate parseTx
        end
        getTxHistory->>getTxHistory: Update cursor
    end
    getTxHistory-->>Client: TxHistoryResponse
    deactivate getTxHistory
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20-25 minutes

Possibly related PRs

  • feat: tron parseTx() handle transfers #11449: Refactors chain adapter transaction parsing by replacing public parseTx with private parse and new private helpers to extract token/internal transfers, with concurrent updates to related types.

Suggested reviewers

  • gomesalexandre

Poem

🐰 A hopping TON adapter, now quite spry,
Fetches jettons from the blockchain sky,
With history, pagination, and addresses made right,
The parser hops faster, reaching new height! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: ton tx history parsing' is concise and directly related to the main changes, which implement transaction history retrieval and parsing logic for TON, including jetton transfers and address resolution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch auto-claude/008-the-ton-implementation-isn-t-parsing-txs-properly-

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@NeOMakinG NeOMakinG changed the title fix: tron tx history parsing fix: ton tx history parsing Jan 21, 2026
@NeOMakinG NeOMakinG marked this pull request as ready for review January 21, 2026 14:58
@NeOMakinG NeOMakinG requested a review from a team as a code owner January 21, 2026 14:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@packages/chain-adapters/src/ton/TonChainAdapter.ts`:
- Around line 443-447: Validate the incoming cursor before converting to an
offset: in the scope where cursor and offset are initialized (used by
fetchTxHistory), check that cursor is a valid numeric string (e.g., digits only
or Number.isFinite(Number(cursor))) and only then set offset = parseInt(cursor,
10); otherwise default offset to 0 (or handle invalid cursor explicitly). Update
the initialization around the cursor/offset variables so offset cannot become
NaN and ensure fetchTxHistory uses this validated offset.
- Around line 796-872: The catch block in the jetton transfer fetch silently
swallows errors; change the try/catch around the this.httpApiRequest call in
TonChainAdapter (the loop handling response.jetton_transfers and using
addressesMatch, toAssetId, and TransferType) to catch the error as a variable
and log a clear contextual error (include txHash and pubkey and the error/stack)
via the adapter logger (e.g., this.logger.error or existing logging facility)
before returning [] so failures are recorded for debugging.
- Around line 960-963: The parseTx method currently coerces non-string inputs to
"[object Object]" causing API failures; update parseTx to either accept only
string hashes by changing its signature to parseTx(txHash: string, pubkey:
string): Promise<Transaction> and remove the fallback conversion, or add an
explicit type guard branch for TonTx objects (e.g., detect TonTx and extract its
hash or required fields) similar to the TRON/SUI pattern; modify the function
body around parseTx and any callers to pass a string hash (or handle TonTx) and
ensure types Transaction and TonTx are used consistently.
- Around line 891-893: The code lowercases addresses when comparing
tx.in_msg.destination, tx.in_msg.source, and pubkey which corrupts user-friendly
base64 TON addresses; update the normalization used by addressesMatch (or the
caller) so only raw TON addresses (e.g., addresses that start with "0:" or are
hex/raw forms) are converted to lowercase, while base64/user-friendly addresses
are left unchanged; implement this by adding a small discriminator (raw-address
pattern vs base64 pattern) and applying .toLowerCase() only for the raw path
before comparing in addressesMatch.

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

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

Def. flaky but merging for the sake of progression, I'll follow-up with a few things here 🙏🏽

Spotted issues:

  • Self-sends not parsed
  • USDT -> TON parsing looking broken
  • Tx hash looking odd with that redirect Tx url
Image Image Image

@gomesalexandre gomesalexandre merged commit 7340a89 into develop Feb 9, 2026
4 checks passed
@gomesalexandre gomesalexandre deleted the auto-claude/008-the-ton-implementation-isn-t-parsing-txs-properly- branch February 9, 2026 10:17
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.

2 participants