Skip to content

feat(tron): estimate send fees conservatively in onAmountInput - #554

Open
ulissesferreira wants to merge 1 commit into
mainfrom
WPN-2375-estimate-fees-conservatively-in-onamountinput
Open

ulissesferreira wants to merge 1 commit into
mainfrom
WPN-2375-estimate-fees-conservatively-in-onamountinput

Conversation

@ulissesferreira

@ulissesferreira ulissesferreira commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

onAmountInput returned valid without checking fees when toAddress was absent. It now builds a probe transaction to the Tron zero address (T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb) and estimates fees, adding the account activation reserve for native TRX. The zero address is used because Tron rejects self-transfers, so the sender's own address cannot serve as the probe. TRC-20 transfers estimate the transfer fee without an activation reserve. This makes typing-time validation consistent with the destination-known case and prepares getMaxSendableAmount.

References

Ticket: WPN-2375

Checklist

  • I have updated the test suite for new or updated code as appropriate
  • I have communicated my changes to consumers by updating changelogs for packages I have changed
  • I have updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I have introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@ulissesferreira
ulissesferreira force-pushed the WPN-2375-estimate-fees-conservatively-in-onamountinput branch from a07d39c to 18d5846 Compare November 4, 2026 16:51
@ulissesferreira ulissesferreira changed the title feat(tron): estimate send fees conservatively in onAmountInput feat(tron): estimate send fees conservatively in onAmountInput Nov 4, 2026
@ulissesferreira
ulissesferreira force-pushed the WPN-2375-estimate-fees-conservatively-in-onamountinput branch 3 times, most recently from d2514de to d8db631 Compare November 5, 2026 11:23
@ulissesferreira
ulissesferreira marked this pull request as ready for review November 5, 2026 11:26
@ulissesferreira
ulissesferreira requested review from a team as code owners November 5, 2026 11:26
@ulissesferreira
ulissesferreira force-pushed the WPN-2375-estimate-fees-conservatively-in-onamountinput branch from d8db631 to c5c45f8 Compare November 5, 2026 12:52

@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.

Looks good! just a couple of small suggestions on the changelog

Comment on lines +569 to 572
const baseTrxFee = new BigNumber(
fees.find((fee) => fee.asset.type === nativeTokenId)?.asset.amount ??
'0',
);

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.

nit (as this was already the case): this falls back to 0 silently in case there's no native token fee, which is unexpected: perhaps we should throw an error in these cases?

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.

What error should we throw?

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.

Actually, this is aligned with what some other methods are doing. So I would suggest if we add an error we do it in another PR, does that sound good?

Comment thread packages/tron-wallet-snap/CHANGELOG.md Resolved
Comment thread packages/tron-wallet-snap/CHANGELOG.md Resolved
@ulissesferreira
ulissesferreira force-pushed the WPN-2375-estimate-fees-conservatively-in-onamountinput branch 3 times, most recently from 82f6570 to 476d65f Compare November 6, 2026 12:44
@ulissesferreira
ulissesferreira force-pushed the WPN-2375-estimate-fees-conservatively-in-onamountinput branch from 476d65f to 5366887 Compare November 6, 2026 12:50
@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Amount validation mishandles empty recipients, can double-count activation fees, and omits activation reserves for TRC-10 transfers, causing incorrect rejections or acceptance of unaffordable sends.

3 open issues
What changed in this PR

This PR adds fee checks to the Tron snap’s amount validation before a recipient is entered, preparing for getMaxSendableAmount.

Changes:

  • Estimates fees using a zero-address probe when the destination is unknown, with an additional activation reserve for native TRX.
  • Extracts reusable account-activation fee calculation and adds validation tests.
  • Documents the behavior change and updates the snap bundle checksum.
File Description
packages/​tron-wallet-snap/​src/​services/​send/​types.ts Adds the activation-fee result type.
packages/​tron-wallet-snap/​src/​services/​send/​FeeCalculatorService.ts Extracts and exposes activation-fee calculation.
packages/​tron-wallet-snap/​src/​services/​send/​FeeCalculatorService.test.ts Tests activation costs, resources, and unavailable chain parameters.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​clientRequest.ts Adds unknown-recipient fee estimation and native TRX activation reserves.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​clientRequest.test.ts Tests fee validation without a recipient for TRX and TRC-20.
packages/​tron-wallet-snap/​snap.manifest.json Updates the bundle checksum.
packages/​tron-wallet-snap/​CHANGELOG.md Documents the amount-validation change.

Review effort: Balanced

const sendTransaction = await this.#sendService.buildTransaction({
fromAccountId: accountId,
toAddress,
toAddress: toAddress ?? NULL_ADDRESS,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To check this one with a null address

* sender's staked Bandwidth cannot cover the account creation.
*/
const activationTrxFee =
!toAddress && isNativeToken
assetId === nativeTokenId ? valueBN.plus(trxFee) : trxFee;
const totalTrxToSpend = (isNativeToken ? valueBN : ZERO)
.plus(baseTrxFee)
.plus(activationTrxFee);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok to check this double calculation in that case

This branch was successfully deployed

1 active (outdated) deployment
default-branch — d8db6316 Deployed Nov 5, 2026 by ulissesferreira via Determine whether this PR is a release PR #2101
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.

4 participants