Repository navigation
feat(tron): add getMaxSendableAmount client request method - #555
Open
ulissesferreira wants to merge 1 commit into
Open
ulissesferreira wants to merge 1 commit into
ulissesferreira wants to merge 1 commit into
Conversation
ulissesferreira
force-pushed
the
WPN-2374-get-max-sendable-amount
branch
from
November 4, 2026 16:52
9c04a39 to
96c6a10
Compare
2 tasks done
getMaxSendableAmount client request method
ulissesferreira
force-pushed
the
WPN-2374-get-max-sendable-amount
branch
from
November 5, 2026 15:58
96c6a10 to
5865cae
Compare
Computes the maximum safe amount that can be sent for TRX and TRC-20 assets, with its fee quote. The sent asset and the account resources are read fresh, so the result never acts on stale balances. For native TRX sends the maximum leaves enough TRX to cover the network fees and the account activation; for TRC-20 sends the account must hold enough TRX to cover the transfer fee. When the destination is omitted, the conservative case is assumed and the quoted fees include a conservative account activation reserve. WPN-2374
ulissesferreira
force-pushed
the
WPN-2374-get-max-sendable-amount
branch
from
November 6, 2026 16:01
5865cae to
6c746b9
Compare
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The maximum-amount calculation can incorrectly return zero when a positive TRX transfer is valid at an encoding boundary, and exponential notation can cause small token maximums to be rejected.
2 open issues
What changed in this PR
Adds getMaxSendableAmount to the Tron Snap’s client API, reusing the balance and fee helpers used by onAmountInput to support maximum-send calculations.
Changes:
- Registers the method and defines request and response validation.
- Calculates TRX and TRC-20 amounts with fee checks and an activation reserve for native transfers without a destination.
- Adds handler tests, documents the API addition, and updates the bundle checksum.
| File | Description |
|---|---|
packages/tron-wallet-snap/src/handlers/clientRequest/validation.ts |
Defines request and response schemas. |
packages/tron-wallet-snap/src/handlers/clientRequest/types.ts |
Adds the client method identifier. |
packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts |
Routes requests and calculates sendable amounts. |
packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts |
Tests balances, fees, activation reserves, and invalid addresses. |
packages/tron-wallet-snap/snap.manifest.json |
Updates the bundle checksum. |
packages/tron-wallet-snap/CHANGELOG.md |
Documents the new client method. |
Review effort: Balanced
| const trxFee = baseTrxFee.plus(activationTrxFee); | ||
|
|
||
| if (isNativeToken) { | ||
| const maxAmount = nativeTokenBalance.minus(trxFee); |
Contributor
There was a problem hiding this comment.
To confirm this behavior with the balance fee
| return { amount: '0' }; | ||
| } | ||
|
|
||
| return { amount: asset.uiAmount }; |
Contributor
There was a problem hiding this comment.
ok little improvement there with this tofixed addition
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





Explanation
Adds the
getMaxSendableAmountclient request method to the Tron Snap. It returns only{ amount }: the maximum amount that can be entered soonAmountInputpasses, or0when no amount can pass. Fees, balances, and validation errors are intentionally not returned.The value is derived from the same balance source (
getAccountAssetsByIDs), fee limit, and fee/reserve helpers asonAmountInput, without a brute-force search. Native TRX subtracts the network fee and, whentoAddressis omitted, the account activation reserve. TRC-20 returns the full token balance when TRX covers the transfer fee, otherwise0.References
Ticket: WPN-2374
Stacked on: #554
Checklist