Skip to content

fix(tron-wallet-snap): price new-account TRX sends as 1 TRX + 100 Bandwidth - #175

Open
Battambang wants to merge 4 commits into
mainfrom
fix/WPN-1408-tron-activation-bandwidth
Open

fix(tron-wallet-snap): price new-account TRX sends as 1 TRX + 100 Bandwidth#175
Battambang wants to merge 4 commits into
mainfrom
fix/WPN-1408-tron-activation-bandwidth

Conversation

@Battambang

@Battambang Battambang commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Explanation

This pull request updates the account activation fee logic for TRON native and TRC-10 token transfers, ensuring that fee estimation for sending to unactivated accounts aligns with the TRON protocol. Specifically, it distinguishes between using staked Bandwidth (costing 1 TRX + 100 Bandwidth) and burning 0.1 TRX when the sender lacks staked Bandwidth, instead of relying on transaction byte size. The changes also add new constants, improve test coverage, and refactor test cases for clarity and correctness.

flow

Fee Calculation Improvements

  • Updated the fee estimation logic to charge 1 TRX plus 100 Bandwidth when activating a new account with sufficient staked Bandwidth, or 0.1 TRX when staked Bandwidth is insufficient, replacing the previous approach based on transaction byte size. [1] [2]
  • Added FALLBACK_CREATE_ACCOUNT_FEE_SUN (0.1 TRX) and FALLBACK_CREATE_NEW_ACCOUNT_FEE_SUN (1 TRX) constants to constants/index.ts for use in fee calculations.

Test Coverage and Refactoring

  • Enhanced and refactored tests in FeeCalculatorService.test.ts to cover scenarios for native and TRC-10 sends to unactivated accounts, including cases with and without staked Bandwidth, and with memo fees. [1] [2] [3] [4] [5] [6] [7] [8]
  • Added utility and type definitions to support the new fee calculation logic and tests. [1] [2] [3]

These changes ensure more accurate and protocol-compliant fee estimates for TRON account activation scenarios.

What the UI array looks like depending of scenario:

  • New account + stake covers 100 → [{ TRX: 1 }, { BANDWIDTH: 100 }]
  • New account + no stake → [{ TRX: 1.1 }]
  • Existing account + enough Bandwidth → [{ TRX: 0 }, { BANDWIDTH: 266 }]

Screenshots

BEFORE:
BEFORE

AFTER:
AFTER

References

https://consensyssoftware.atlassian.net/browse/WPN-1408

Checklist

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

…dwidth

Activation was billed as TransferContract byte size (~266) plus 1 TRX,
which overstated Testing Day costs. Use create-account Bandwidth from
chain params, staked quota only, and a 0.1 TRX shortfall instead.
@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@2.0.1-preview-73bc702
@metamask-previews/snap-networks-utils@1.0.0-preview-73bc702
@metamask-previews/solana-wallet-snap@6.0.0-preview-73bc702
@metamask-previews/stellar-wallet-snap@0.0.1-preview-73bc702
@metamask-previews/tron-wallet-snap@3.1.0-preview-73bc702

@Battambang
Battambang marked this pull request as ready for review August 19, 2026 16:32
@Battambang
Battambang requested a review from a team as a code owner August 19, 2026 16:33
@Battambang
Battambang deployed to default-branch August 19, 2026 16:33 — with GitHub Actions Active
@Battambang
Battambang requested a balanced review from Copilot August 19, 2026 16:34

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.

Pull request overview

Updates TRON account-activation fee estimation to use protocol-defined fees and staked Bandwidth.

Changes:

  • Adds dynamic activation-fee and Bandwidth calculations for TRX/TRC-10 transfers.
  • Expands activation and memo-fee tests.
  • Updates package metadata and changelog.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
FeeCalculatorService.ts Implements activation fee estimation.
FeeCalculatorService.test.ts Adds activation scenarios.
constants/index.ts Adds fallback fee constants.
snap.manifest.json Updates bundle checksum.
CHANGELOG.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/tron-wallet-snap/src/services/send/FeeCalculatorService.ts
Comment on lines +806 to +809
const bandwidthQuota =
transactionFeeSun > 0
? BigNumber(createAccountFeeSun).div(transactionFeeSun)
: BigNumber(createAccountFeeSun).div(FALLBACK_GET_TRANSACTION_FEE_SUN);
# Conflicts:
#	packages/tron-wallet-snap/snap.manifest.json
type ActivationAssessment = {
unactivatedCount: number;
ownerAddress: string | undefined;
};

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.

Let's move these types to types.ts, what do you think?

const activation = await this.#assessAccountActivation({
scope,
transaction,
});

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.

Why do we need so much code to check activation when we have the isAccountActivated method? Do we really need to fetch transactions and all that? Am I missing something?

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.

3 participants