Conversation
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
FiatStrategy and getQuotes functionalityFiatStrategy and getQuotes functionality
FiatStrategy and getQuotes functionalityFiatStrategy and getQuotes functionality
|
@SocketSecurity ignore npm/@metamask/ramps-controller@12.0.0 |
| ### Added | ||
|
|
||
| - **BREAKING:** Add `AssetsControllerGetStateForTransactionPayAction` to the `AllowedActions` messenger type ([#8163](https://github.com/MetaMask/core/pull/8163)) | ||
| - Add MMPay `FiatStrategy` quotes flow ([#8121](https://github.com/MetaMask/core/pull/8121)) |
There was a problem hiding this comment.
| - Add MMPay `FiatStrategy` quotes flow ([#8121](https://github.com/MetaMask/core/pull/8121)) | |
| - Add `FiatStrategy` to retrieve quotes via `RampsController` ([#8121](https://github.com/MetaMask/core/pull/8121)) |
| export const POLYGON_USDCE_ADDRESS = | ||
| '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' as Hex; | ||
|
|
||
| export type TransactionPayFiatAsset = { |
There was a problem hiding this comment.
Should all of the be in strategy/fiat/[types|consants].ts?
There was a problem hiding this comment.
Moved to strategy/fiat/constants.ts and strategy/fiat/utils.ts
|
|
||
| import type { RelayQuote } from '../relay/types'; | ||
|
|
||
| export type FiatOriginalQuote = { |
There was a problem hiding this comment.
Minor, in the context of this controller, could this just be FiatQuote?
| import type { RelayQuote } from '../relay/types'; | ||
|
|
||
| export type FiatOriginalQuote = { | ||
| fiatQuote: Quote; |
There was a problem hiding this comment.
Would it add clarity to call this rampsQuote as "Fiat" is our abstraction over Ramps and Relay together?
There was a problem hiding this comment.
Good call, renamed to rampsQuote
| provider: FiatValue; | ||
|
|
||
| /** Fee charged by fiat on-ramp provider. */ | ||
| fiatProvider?: FiatValue; |
There was a problem hiding this comment.
providerFiat?
Or should we be more generic and call this providerSecondary so we can have a mechanism to have a more granular fee and the client can choose what to call it?
There was a problem hiding this comment.
Went with providerFiat for now, we can generalize later if needed
|
|
||
| function getRampsProviderFee(fiatQuote: RampsQuote): BigNumber { | ||
| return new BigNumber(fiatQuote.quote.providerFee ?? 0).plus( | ||
| fiatQuote.quote.networkFee ?? 0, |
There was a problem hiding this comment.
Nice, so they obviously handle any network fees, but include it separately?
There was a problem hiding this comment.
Exactly, not sure how accurate that is but it's definitely in the quote as I saw from testing.
| fiat: metaMaskFee, | ||
| usd: metaMaskFee, | ||
| }, | ||
| provider: relayQuote.fees.provider, |
There was a problem hiding this comment.
For consistency, this needs to be the total provider fee for the quote, so ramps + relay.
Meaning we can calculate the Relay portion if needed in the client by subtracting the fiatProvider value.
There was a problem hiding this comment.
fees.provider is now relay + ramps combined; providerFiat is the ramps-only breakdown.
| } | ||
| } | ||
|
|
||
| return MMPAY_FIAT_ASSET_ID_BY_TX_TYPE[transactionType as TransactionType]; |
There was a problem hiding this comment.
Done, renamed to FIAT_ASSET_ID_BY_TX_TYPE
| tx.metamaskPay = { | ||
| bridgeFeeFiat: totals.fees.provider.usd, | ||
| bridgeFeeFiat: totals.fees.fiatProvider | ||
| ? new BigNumber(totals.fees.provider.usd) |
There was a problem hiding this comment.
As mentioned in other comment, this shouldn't be needed as provider always needs to be the total.
| .toString(10); | ||
|
|
||
| const totalUsd = new BigNumber(providerFee.usd) | ||
| .plus(fiatProviderFee.usd) |
There was a problem hiding this comment.
Also here, this is an additional optional breakdown, but provider remains the total provider fee.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| // TODO: Implement provider selection logic; force Transak staging for now. | ||
| (quote) => quote.provider === '/providers/transak-native-staging', | ||
| ); | ||
| } |
There was a problem hiding this comment.
Hardcoded staging provider blocks production fiat quotes
Medium Severity
pickBestFiatQuote only matches the staging provider string '/providers/transak-native-staging'. In any non-staging environment the ramps response will use a different provider identifier, causing this function to always return undefined and the fiat strategy to produce no quotes.


Explanation
This PR introduces
FiatStrategy:TransactionPayStrategy.Fiatand registersFiatStrategyin strategy resolution.MMPAY_FIAT_ASSET_ID_BY_TX_TYPE).fiat-quotes.tswith relay-first estimation:fiatPayment.amountFiat+ selected payment methodstrategy: fiatquotefees.provider= relay provider/swap feefees.fiatProvider= ramps provider/network feefees.metaMask= MM fee (100 bps overamountFiat + adjustedAmountFiat)metamaskPay.bridgeFeeFiatwhen fiat provider fee exists.References
Checklist
Note
Medium Risk
Adds a new quoting path that combines relay fee estimation with fiat on-ramp quotes and introduces new fee breakdown fields, which could affect quote selection and totals calculations. Risk is moderated by extensive unit tests and the submit path being a placeholder.
Overview
Adds a new
TransactionPayStrategy.Fiatand registersFiatStrategy, enabling MM Pay to return combined fiat+relay quotes by first estimating relay fees, then requestingRampsController:getQuoteswith an adjusted fiat amount.Extends the quote/totals data model to carry
fiatPaymentMethodthrough quoting and to include an optionalfees.providerFiatbreakdown (fiat on-ramp provider/network fees), and updates totals aggregation and metadata sync logic accordingly.Wires in
@metamask/ramps-controller(deps + TS references), adds fiat-asset mappings by transaction type, introducescomputeRawFromFiatAmount, and includes comprehensive tests for the new fiat quote flow and edge cases.Written by Cursor Bugbot for commit ee9b3b7. This will update automatically on new commits. Configure here.