Skip to content

feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694

Open
OGPoyraz wants to merge 12 commits into
mainfrom
ogp/fiat-order-txhash-implementation
Open

feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694
OGPoyraz wants to merge 12 commits into
mainfrom
ogp/fiat-order-txhash-implementation

Conversation

@OGPoyraz
Copy link
Copy Markdown
Member

@OGPoyraz OGPoyraz commented May 5, 2026

Explanation

1. Derive fiat order sourceAmount from on-chain tx data

Currently, the fiat submit flow derives sourceAmountRaw from order.cryptoAmount - a human-readable value reported by the on-ramp provider. This value may not precisely reflect what was actually received on-chain.

This PR reads the actual transferred amount from the completed on-chain transaction (order.txHash) instead. For native tokens, the amount is taken from tx.value. For ERC-20 tokens, the amount is decoded from the transfer(address,uint256) call data. If the on-chain read fails or the transaction hash is missing, the existing order.cryptoAmount derivation is used as a fallback.

The implementation introduces:

  • getTransferredAmountFromTxHash - a generic utility in utils/transaction-receipt.ts that reads transferred amounts from any on-chain transaction (native or ERC-20). Takes explicit chainId and tokenAddress params for reusability.
  • resolveSourceAmountRaw - a fiat-strategy-specific function in strategy/fiat/utils.ts that orchestrates the on-chain read with order.cryptoAmount fallback.
  • getRawSourceAmountFromOrderCryptoAmount - the existing decimal-shift conversion, moved from fiat-submit.ts to strategy/fiat/utils.ts and renamed for clarity.

2. Persist fiat order metadata on metamaskPay

The TransactionPayController state is cleaned up when a transaction is finalized (confirmed/failed/dropped). This means fiatPayment.orderId and the provider info are gone by the time the user opens the activity/transaction-details view.

To enable the mobile activity view to show a fiat order status row (and query RampsController:getOrder for live status), this PR persists the fiat order ID and provider code on transaction.metamaskPay before polling begins in submitFiatQuotes.

Changes:

  • MetamaskPayMetadata (transaction-controller/types.ts) — Added fiatOrderId?: string and fiatProvider?: string fields.
  • submitFiatQuotes (fiat-submit.ts) — Calls updateTransaction to persist fiatOrderId and fiatProvider on tx.metamaskPay before waitForOrderCompletion starts polling. This ensures data is available even while the order is still in-flight.
  • Tests — Two new tests verify metadata persistence and that existing metamaskPay fields are preserved.

References

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

Note

Medium Risk
Touches the fiat submission path by introducing on-chain transaction reads and persisting new metadata onto transactions; failures or unexpected tx shapes could affect quote amounts or activity display, though fallbacks and tests mitigate this.

Overview
Improves MetaMask Pay fiat submissions by deriving the relay sourceAmountRaw from the completed on-chain transaction (order.txHash) when possible (native tx.value or decoded ERC-20 transfer calldata), falling back to order.cryptoAmount if the read fails or is unavailable.

Persists fiat on-ramp order identifiers onto the transaction (transaction.metamaskPay.fiatOrderId / fiatProvider) before order polling begins so downstream activity views can query order status even after controller state cleanup. Adds a reusable getTransferredAmountFromTxHash utility plus new/updated unit tests and changelog entries.

Reviewed by Cursor Bugbot for commit 3535057. Bugbot is set up for automated code reviews on this repo. Configure here.

@OGPoyraz OGPoyraz requested review from a team as code owners May 5, 2026 11:40
@OGPoyraz OGPoyraz changed the title feat: derive fiat order source amount from on-chain tx data feat: Derive fiat order sourceAmount from on-chain tx data May 5, 2026
Comment thread packages/transaction-pay-controller/src/strategy/fiat/utils.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eb1964b. Configure here.

@OGPoyraz OGPoyraz changed the title feat: Derive fiat order sourceAmount from on-chain tx data feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata May 11, 2026
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.

1 participant