Skip to content

fix(sdk-coin-flrp): subtract minImportToPFee from ExportInC outputAmount#9120

Merged
ArunBala-Bitgo merged 1 commit into
masterfrom
CECHO-1450-fix-pending-flrp-import-amount
Jun 26, 2026
Merged

fix(sdk-coin-flrp): subtract minImportToPFee from ExportInC outputAmount#9120
ArunBala-Bitgo merged 1 commit into
masterfrom
CECHO-1450-fix-pending-flrp-import-amount

Conversation

@bitgo-ai-agent-dev

Copy link
Copy Markdown

What

  • In Flrp.explainTransaction, when the transaction is a C-chain export (ExportInC), subtract the network's minImportToPFee from outputAmount and each output's amount before returning.
  • Add a unit test verifying that both unsigned and signed ExportInC transactions return the adjusted (net) output amount when explained via the FLRP coin.

Why

  • For C→P imports, the wallet platform calls Flrp.explainTransaction on the ExportInC transaction to display the pending import amount on the FLRP P-chain wallet (before the ImportInP is confirmed). The ExportInC exportedOutputs hold the gross P-chain UTXO amount — which includes the import fee premium — so the pending display showed a higher-than-actual amount. After the ImportInP confirmed, the blockchain showed the true net P-chain credit, causing the discrepancy between pending and confirmed amounts reported in CECHO-1450.
  • Subtracting minImportToPFee from the displayed amount yields the expected minimum net P-chain receipt, aligning the pending display with the confirmed balance.
  • The verifyTransaction path continues to use the raw tx.explainTransaction() output (gross UTXO amount) for validation, so existing export amount-range checks are unaffected.

Test plan

  • yarn unit-test in modules/sdk-coin-flrp — 362 tests passing, including the new test for adjusted ExportInC outputAmount.
  • yarn lint in modules/sdk-coin-flrp — clean.
  • End-to-end: initiate a C→P import on a FLRP hot wallet and custodial wallet in staging; verify the pending transaction shows the same amount as the confirmed P-chain balance.

Ticket: CECHO-1450

For C→P imports, the wallet platform shows the ExportInC transaction
as the pending import amount on the FLRP (P-chain) wallet before the
ImportInP is confirmed. The ExportInC exportedOutputs hold the gross
P-chain UTXO amount (which includes the import fee premium), causing
the pending display to show a higher amount than the actual P-chain
credit delivered by the ImportInP.

Fix: in `Flrp.explainTransaction`, when the transaction is a C-chain
export (ExportInC), subtract the network's `minImportToPFee` from the
`outputAmount` and each output's amount. This yields the minimum
expected net P-chain receipt, aligning the pending display with the
confirmed P-chain balance and resolving the amount discrepancy reported
in CECHO-1450.

The `verifyTransaction` path continues to use the gross UTXO amount for
validation (via `tx.explainTransaction()` directly), so existing export
validation logic is unaffected.

Ticket: CECHO-1450
Session-Id: 53bbdb3d-3f67-4bc4-b5cd-a8be1b2d8857
Task-Id: 99e7fafb-287d-487c-b5fb-9c7f4c2f28f7
@linear-code

linear-code Bot commented Jun 25, 2026

Copy link
Copy Markdown

CECHO-1450

@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot force-pushed the CECHO-1450-fix-pending-flrp-import-amount branch from 87f9f68 to d9434aa Compare June 25, 2026 15:16
@ArunBala-Bitgo

Copy link
Copy Markdown
Contributor

@claude review as grug. Analyse if this PR solves the import amount discrepancy

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Claude finished @ArunBala-Bitgo's task —— View job


Grug Review of FLRP Import Amount Fix

Grug analyze if PR fix import amount discrepancy. Grug make todo:

  • Read changed files to understand fix
  • Check if fix solve problem correctly
  • Look for grug-concerns (edge cases, bugs)
  • Give grug verdict

Grug Understand Problem

Grug read code. Problem is:

  1. C→P export transaction (ExportInC) send money from C-chain to P-chain
  2. Transaction output amount include gross amount (with import fee premium)
  3. Wallet platform show pending amount using explainTransaction() before ImportInP confirmed
  4. User see higher amount than what actually get on P-chain after ImportInP confirmed
  5. Discrepancy make user confused - pending show more than confirmed balance

Grug Look at Fix

Grug see fix in flrp.ts:440-452. Fix do this:

  1. Check if ExportInC transaction: tx.isTransactionForCChain && explanation.type === TransactionType.Export
  2. Get minimum import fee: minImportToPFee = BigInt((this._staticsCoin.network as FlareNetwork).minImportToPFee)
  3. Subtract fee from output amount: adjustedOutputAmount = (BigInt(explanation.outputAmount) - minImportToPFee).toString()
  4. Subtract fee from each output: amount: (BigInt(o.amount) - minImportToPFee).toString()
  5. Return adjusted explanation with net amounts

Grug see test confirm fix work for both unsigned and signed ExportInC transactions.

Grug Check Fix Logic

Fix solve problem correctly:

  • Fix only affect explainTransaction() path used for display
  • verifyTransaction() still use raw tx.explainTransaction() (line 96) - no adjustment applied during validation
  • This preserve existing export amount-range checks in validateExportTx() (lines 164-173)
  • User see net amount in pending display, validation still use gross amount for safety

Fix target right scenario:

  • Only apply when tx.isTransactionForCChain && explanation.type === TransactionType.Export
  • This is exactly C→P export scenario that cause problem
  • No affect other transaction types

Test coverage good:

  • Test verify both unsigned and signed ExportInC return adjusted amount
  • Test use actual minImportToPFee value from testnet config: 1261000
  • Test check both outputAmount and individual output amount fields

Grug Spot Concerns

🟡 Grug see potential edge cases but acceptable:

  1. Negative amount possible: If outputAmount < minImportToPFee, result is negative string. But this should never happen in real scenario - ExportInC must have enough amount to cover import fee.
  2. Fee values consistency: Code use minImportToPFee for display but maxImportFee for validation. This correct - show minimum expected, validate with maximum allowed range.
  3. No fee validation: Fix assume minImportToPFee always exist on network config. This safe assumption for FLRP.

Good separation of concerns: explainTransaction() for display vs verifyTransaction() for validation use different logic paths.

Grug Final Verdict

🟢 GRUG APPROVE THIS FIX

Why grug think fix good:

  • Fix target exact problem described in CECHO-1450
  • Smart solution: adjust display amount, keep validation unchanged
  • Test verify fix work correctly
  • No break existing functionality
  • Follow good practice: separate display logic from validation logic

What fix accomplish:

  • Pending C→P import now show net amount user will actually receive
  • No more confusion when pending amount different from confirmed amount
  • Existing validation logic remain intact and safe

Grug recommend: Ship this fix. It solve real user problem with minimal risk.

@ArunBala-Bitgo ArunBala-Bitgo marked this pull request as ready for review June 26, 2026 08:14
@ArunBala-Bitgo ArunBala-Bitgo requested a review from a team as a code owner June 26, 2026 08:14

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

LG

@ArunBala-Bitgo ArunBala-Bitgo merged commit 36d4545 into master Jun 26, 2026
24 checks passed
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