Skip to content

fix(near): correct token attribution in tx parsing, harden intents actuals - #12525

Merged
kaladinlight merged 2 commits into
developfrom
fix/near-intents-decimal-scaling
Aug 4, 2026
Merged

fix(near): correct token attribution in tx parsing, harden intents actuals#12525
kaladinlight merged 2 commits into
developfrom
fix/near-intents-decimal-scaling

Conversation

@kaladinlight

Copy link
Copy Markdown
Member

Description

A NEAR Intents swap (NEAR → USDT on NEAR) displayed an absurd completed amount ("5,651,948,527,226,708,191.126278 USDT" for a ~1 USDT swap). Investigation traced every source feeding the displayed actual amount; two real defects were found and fixed on those paths:

  • parseTx token mis-attribution: every NEP-141 event in a transaction was labeled with the transaction's top-level receiver as the token contract. For intents settlements (receiver intents.near), the USDT ft_transfer to the user was attributed to nep141:intents.near, so useActualBuyAmountCryptoPrecision's chain-side lookup could never match the buy asset and the fallback chain silently failed. Events are now attributed per-receipt to the executor — the contract that actually emitted the event — which is correct for any transaction shape (delegated, batched, multi-contract).
  • Intents checkTradeStatus over-trusted swapDetails.amountOut: it was reported as actualBuyAmountCryptoBaseUnit in every status. It is only reliably destination-denominated on terminal SUCCESS; in-flight and refund states no longer supply it, so a transient settlement-phase value can never be persisted as the actual amount (once written, it was never re-read from a corrected poll if polling stopped).

Verified live against the affected swap's settlement transaction (DJaLoG… / deposit c0f7e4…): the parse now returns exactly Receive 996459 under near:mainnet/nep141:usdt.tether-token.near — matching the provider's own swapDetails.amountOut and explorer (0.996459 USDT). Also verified the full quote path is decimals-clean end to end: provider registry (6 decimals), our asset (precision 6), request amount (wNEAR 24dp), quote amountOut (6dp).

Issue (if applicable)

closes #

Risk

Low. NEAR-only parsing plus one status-field gate. The executor attribution strictly improves correctness for all NEP-141 event shapes; plain ft_transfer transactions (receiver = token contract = executor) are unchanged.

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

NEAR transaction parsing for display/actual-amount purposes and NEAR Intents swap status reporting. No transaction construction changes.

Testing

Engineering

  • Live parseTx against the affected settlement tx before/after: mislabeled nep141:intents.near → correct nep141:usdt.tether-token.near, value exact (996459).
  • Full event dump of all three NEAR transactions of the swap via archival RPC confirms the corrupted figure exists nowhere on-chain — it could only be app-side, on the paths fixed here.
  • 1-click status and SDK responses verified to carry the correct 6-decimal amountOut on SUCCESS.
  • tsc clean on chain-adapters and swapper.

Operations

  • Do a NEAR Intents swap into a NEAR-chain token: the completion notification and action center should show the actual received amount at sane magnitude.

Screenshots (if applicable)

🤖 Generated with Claude Code

…tuals

A NEAR intents swap displayed an absurd USDT amount. Two defects on the
actual-buy-amount paths:

- parseTx labeled every nep141 event with the transaction's top-level
  receiver as token contract, so a settlement's USDT transfer to the
  user was attributed to intents.near - the actual-amount lookup never
  matched the buy asset and fell through. Events are now attributed to
  the receipt's executor, the contract that actually emitted them.
- near-intents checkTradeStatus reported swapDetails.amountOut as the
  actual buy amount in every state - it is only destination-denominated
  on terminal success, so in-flight and refund states no longer supply
  it.

Verified live against the affected settlement tx: the parse now returns
the exact received amount under the correct usdt.tether-token.near
asset id.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kaladinlight
kaladinlight requested a review from a team as a code owner August 4, 2026 21:30
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@kaladinlight, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b41c3080-936a-44e9-a0e3-2d2959221671

📥 Commits

Reviewing files that changed from the base of the PR and between 20770dc and 14682b3.

📒 Files selected for processing (2)
  • packages/chain-adapters/src/near/NearChainAdapter.ts
  • packages/swapper/src/swappers/NearIntentsSwapper/endpoints.ts

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.

@kaladinlight
kaladinlight enabled auto-merge (squash) August 4, 2026 22:34
@kaladinlight
kaladinlight merged commit 32ecf2b into develop Aug 4, 2026
4 checks passed
@kaladinlight
kaladinlight deleted the fix/near-intents-decimal-scaling branch August 4, 2026 22:46
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.

1 participant