Skip to content

fix(tron): handle native TRX deposit value and balance#1044

Merged
pedromcunha merged 2 commits into
mainfrom
cozy/fix-tron-native-trx
Jun 26, 2026
Merged

fix(tron): handle native TRX deposit value and balance#1044
pedromcunha merged 2 commits into
mainfrom
cozy/fix-tron-native-trx

Conversation

@cozy-hn

@cozy-hn cozy-hn commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Native TRX (zero-address sentinel) was treated like a TRC-20 token on both the write and read paths.

Write path (relay-tron-wallet-adapter): the triggersmartcontract body omitted call_value, so depositNative ran with 0 TRX attached — deposit mined SUCCESS but the swap was never funded. Now forwards parameter.call_value.

SDK types: added call_value?: number to the Tron TransactionStepItem parameter.

Read path (useTronBalance):

  • Fixed the native sentinel to T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb (decodes to the zero address). The old value pointed at a real contract, so native TRX wrongly fell through to a balanceOf call.
  • Read balance from the top-level getaccount response (it was reading data.result.balance, which is always empty → 0).
  • Throw on triggerconstantcontract failures instead of silently returning a 0 balance.

Verified the sentinel against the prod currency row + /chains API, and call_value against the solver backend source.

Native TRX (the zero-address sentinel) was mishandled as a TRC-20 token
on both the write and read paths:

- relay-tron-wallet-adapter: the triggersmartcontract body omitted
  call_value, so a native depositNative call executed with 0 TRX
  attached (deposit mined SUCCESS but the swap never funded, fill
  failed). Forward parameter.call_value as the tx value.
- sdk: add call_value to the Tron TransactionStepItem parameter type.
- useTronBalance: the native sentinel was hardcoded to a wrong address,
  so native TRX fell through to a balanceOf contract call (which fails
  with "Smart contract is not exist" since the sentinel is not a
  contract). Use the correct native sentinel and guard an empty result.
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
relay-sdk-demo Ready Ready Preview, Comment Jun 26, 2026 5:26pm

Request Review

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Claude finished @cozy-hn's task in 52s —— View job


Code Review — PR #1044

  • Read diff and changed files
  • Review correctness, error handling, repo guidelines
  • Post review

Code Review -- No issues found.

Reviewed 4 files, 30 lines changed. Checked for correctness, security, error handling, and repo guidelines compliance.

A few notes confirming the changes hold up (not issues):

  • adapter.ts:45call_value: stepItem.data.parameter?.call_value ?? 0. The ?? 0 reads like a fallback default on a value field, but 0 is the semantically correct call value for non-payable TRC-20 calls (which omit call_value), so this is correct domain logic rather than a default masking a missing input.
  • useTronBalance.ts:167 — switching to data as Partial<TronAccountResponse> and reading the top-level balance is correct for the TronGrid getaccount shape; empty accounts return {}, so result.balance ?? 0 safely yields 0.
  • useTronBalance.ts:198-210 — the new guards correctly distinguish success (result: { result: true } → no throw) from failure, and the !hex guard prevents the prior BigInt('0x' + undefined) crash. Both surface real errors instead of silently returning a 0 balance.
  • call_value as number — precision is fine in practice (JS safe-integer ceiling ≈ 9e15 sun ≈ 9B TRX), and it matches the backend's Number(amount) emission.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Claude finished @cozy-hn's task in 1m 0s —— View job


📝 Docs Drift Check — No docs impact

This PR does not touch surfaces that require a relayprotocol/relay-docs update.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Claude finished @cozy-hn's task in 50s —— View job


Code Review — PR #1044

  • Read diff and changed files
  • Review correctness, error handling, repo guidelines
  • Post review

Code Review -- No issues found.

Reviewed 4 files, 30 lines changed. Checked for correctness, security, error handling, and repo guidelines compliance.

Notes confirming the changes hold up (not issues):

  • adapter.ts:45call_value: stepItem.data.parameter?.call_value ?? 0 is correct domain logic: 0 is the right call value for non-payable TRC-20 calls (which omit call_value), not a fallback masking a missing critical input. The fix correctly funds native-TRX deposits that previously mined SUCCESS with 0 TRX attached.
  • useTronBalance.ts:167 — reading the top-level balance via data as Partial<TronAccountResponse> matches the TronGrid getaccount shape (balance is top-level, not under data.result). Empty accounts return {}, so result.balance ?? 0 safely yields 0.
  • useTronBalance.ts:198–210 — the new guards correctly distinguish success (result: { result: true }, no code → no throw) from failure, and the !hex guard prevents the prior BigInt('0x' + undefined) crash. Both now surface real errors instead of silently returning a 0 balance.
  • Sentinel address — the native-TRX sentinel change is a value swap verified by the author against the prod currency row + /chains API; the comment correctly documents that it decodes to the zero address.
  • call_value as number — precision is acceptable in practice (JS safe-integer ceiling ≈ 9e15 sun ≈ 9B TRX) and matches the backend's Number(amount) emission.
    cozy/fix-tron-native-trx

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Claude finished @cozy-hn's task in 54s —— View job


📝 Docs Drift Check — No docs impact

This PR does not touch surfaces that require a relayprotocol/relay-docs update.

@pedromcunha pedromcunha merged commit b61e540 into main Jun 26, 2026
6 checks passed
@pedromcunha pedromcunha deleted the cozy/fix-tron-native-trx branch June 26, 2026 17:58
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