@metamask-previews/transaction-pay-controller 28.0.2-preview-6616ef8e1 → 28.0.2-preview-d27fd1d8f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +1 -5
  2. package/dist/strategy/fiat/fiat-direct-musd.d.ts.map +1 -1
  3. package/dist/strategy/fiat/fiat-direct-musd.js +26 -25
  4. package/dist/strategy/fiat/fiat-direct-musd.js.map +1 -1
  5. package/dist/strategy/fiat/fiat-quotes.d.ts.map +1 -1
  6. package/dist/strategy/fiat/fiat-quotes.js +17 -5
  7. package/dist/strategy/fiat/fiat-quotes.js.map +1 -1
  8. package/dist/strategy/fiat/utils.d.ts +33 -8
  9. package/dist/strategy/fiat/utils.d.ts.map +1 -1
  10. package/dist/strategy/fiat/utils.js +60 -11
  11. package/dist/strategy/fiat/utils.js.map +1 -1
  12. package/dist/strategy/relay/constants.d.ts +0 -1
  13. package/dist/strategy/relay/constants.d.ts.map +1 -1
  14. package/dist/strategy/relay/constants.js +0 -1
  15. package/dist/strategy/relay/constants.js.map +1 -1
  16. package/dist/strategy/relay/{relay-max.d.ts → relay-max-gas-station.d.ts} +1 -15
  17. package/dist/strategy/relay/relay-max-gas-station.d.ts.map +1 -0
  18. package/dist/strategy/relay/{relay-max.js → relay-max-gas-station.js} +2 -144
  19. package/dist/strategy/relay/relay-max-gas-station.js.map +1 -0
  20. package/dist/strategy/relay/relay-quotes.d.ts.map +1 -1
  21. package/dist/strategy/relay/relay-quotes.js +10 -40
  22. package/dist/strategy/relay/relay-quotes.js.map +1 -1
  23. package/dist/strategy/relay/relay-submit-execute.d.ts +0 -1
  24. package/dist/strategy/relay/relay-submit-execute.d.ts.map +1 -1
  25. package/dist/strategy/relay/relay-submit-execute.js +3 -3
  26. package/dist/strategy/relay/relay-submit-execute.js.map +1 -1
  27. package/dist/types.d.ts +2 -2
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/types.js.map +1 -1
  30. package/dist/utils/feature-flags.d.ts +1 -25
  31. package/dist/utils/feature-flags.d.ts.map +1 -1
  32. package/dist/utils/feature-flags.js +1 -35
  33. package/dist/utils/feature-flags.js.map +1 -1
  34. package/dist/utils/quotes.d.ts.map +1 -1
  35. package/dist/utils/quotes.js +0 -14
  36. package/dist/utils/quotes.js.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/strategy/relay/relay-max.d.ts.map +0 -1
  39. package/dist/strategy/relay/relay-max.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -10,11 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  ### Changed
11
11
 
12
12
  - Use the native Transak buy quote's fee for the MM Pay fiat estimate when Transak Native is the resolved provider, falling back to the aggregator quote's fee when native is unavailable or the lookup fails ([#9317](https://github.com/MetaMask/core/pull/9317))
13
- - The native lookup and fee reconciliation are owned by `RampsController:getQuoteWithFees`; clients must delegate `RampsController:getQuoteWithFees` to the `TransactionPayController` messenger (the previously required `TransakService:getBuyQuote` delegation is no longer needed) ([#10238](https://github.com/MetaMask/core/pull/10238)).
13
+ - The fee is read via the stateless `TransakService:getBuyQuote` action so the estimate does not write the shared native buy-quote state used by Unified Buy; clients must delegate `TransakService:getBuyQuote` to the `TransactionPayController` messenger.
14
14
  - Charge direct Monad mUSD on-ramp fees on top of the entered amount (fee-on-top), so the total is the entered amount plus fees ([#9317](https://github.com/MetaMask/core/pull/9317))
15
- - Subsidized (fixed-spread) max direct Money Account Relay deposits now use `EXACT_OUTPUT` quoting with vault calls embedded atomically in the Relay quote. ([#10224](https://github.com/MetaMask/core/pull/10224))
16
- - Failed atomic promotions are terminal `no-quotes` errors prefixed with `Atomic promotion failed`, and will block rather than silently fall back.
17
- - Non-subsidized max behavior is unchanged.
18
15
  - Bump `@metamask/utils` from `^11.12.0` to `^12.0.0` ([#10192](https://github.com/MetaMask/core/pull/10192))
19
16
  - Bump `@metamask/assets-controller` from `^16.0.0` to `^16.1.0` ([#10242](https://github.com/MetaMask/core/pull/10242))
20
17
  - Bump `@metamask/assets-controllers` from `^112.0.1` to `^112.0.2` ([#10242](https://github.com/MetaMask/core/pull/10242))
@@ -22,7 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
19
 
23
20
  ### Fixed
24
21
 
25
- - Fall back to the entered fiat amount, rather than the crypto output amount, when a direct mUSD quote is missing `amountOutInFiat`, so a crypto value is not placed in the fiat target field ([#10238](https://github.com/MetaMask/core/pull/10238))
26
22
  - Detect nested `perpsDepositAndOrder` and `predictDepositAndOrder` transactions when selecting `EXACT_OUTPUT` Relay quotes ([#10222](https://github.com/MetaMask/core/pull/10222))
27
23
  - Clear stale quote errors when the payment token changes ([#10239](https://github.com/MetaMask/core/pull/10239))
28
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"fiat-direct-musd.d.ts","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-direct-musd.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACX,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM3C,OAAO,KAAK,EACV,yBAAyB,EACzB,2BAA2B,EAE3B,2BAA2B,EAC3B,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAW5C;;;;;;;;;;;GAWG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,aAAa,GACd,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,2BAA2B,CAAC,WAAW,CAAC,CAAC;IACpD,mBAAmB,EAAE,GAAG,CAAC;IACzB,aAAa,EAAE,2BAA2B,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;CACvB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AAS,CAAC,CA2DtD;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,GAC/D,OAAO,CAET;AAED;;;;;;;GAOG;AACH,wBAAsB,mCAAmC,CAAC,EACxD,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;CAC/C,GAAG,OAAO,CAAC;IAAE,eAAe,CAAC,EAAE,GAAG,CAAA;CAAE,CAAC,CA4BrC"}
@@ -7,7 +7,7 @@ import { getFiatVaultDisabled } from '../../utils/feature-flags.js';
7
7
  import { submitMoneyAccountVaultDeposit } from '../../utils/ma-vault-deposit.js';
8
8
  import { buildCaipAssetType, getTokenInfo } from '../../utils/token.js';
9
9
  import { MUSD_MONAD_FIAT_ASSET } from './constants.js';
10
- import { getRampsQuote, getRawSourceAmountFromOrderCryptoAmount, resolveSourceAmountRaw, validateOrderAsset, } from './utils.js';
10
+ import { getNativeTransakRampsFee, getRampsQuote, getRawSourceAmountFromOrderCryptoAmount, resolveSourceAmountRaw, validateOrderAsset, } from './utils.js';
11
11
  const log = createModuleLogger(projectLogger, 'fiat-direct-musd');
12
12
  const DIRECT_MUSD_ERROR_PREFIX = 'Direct mUSD: ';
13
13
  /**
@@ -28,9 +28,6 @@ export async function getDirectMusdFiatQuote({ amountFiat, fiatPaymentMethod, me
28
28
  if (!Number.isFinite(adjustedAmount) || adjustedAmount <= 0) {
29
29
  throw new Error('Invalid fiat amount for direct mUSD quote');
30
30
  }
31
- // `getRampsQuote` requests `getQuoteWithFees`, so a Transak Native quote
32
- // already carries the native fee (fee-on-top for direct mUSD) in its
33
- // provider/network fee fields.
34
31
  const fiatQuote = await getRampsQuote({
35
32
  adjustedAmount,
36
33
  errorMessage: 'No matching ramps quote found for direct mUSD provider',
@@ -39,6 +36,18 @@ export async function getDirectMusdFiatQuote({ amountFiat, fiatPaymentMethod, me
39
36
  messenger,
40
37
  walletAddress: moneyAccountAddress,
41
38
  });
39
+ // When Transak Native is the resolved provider, prefer its own quote's fee
40
+ // so the estimate matches what Transak Native will charge. Direct mUSD is
41
+ // fee-on-top (the fee is added to the entered amount), so request the native
42
+ // quote in that mode.
43
+ const nativeRampsFee = await getNativeTransakRampsFee({
44
+ adjustedAmount,
45
+ fiatAsset: MUSD_MONAD_FIAT_ASSET,
46
+ fiatPaymentMethod,
47
+ fiatQuote,
48
+ isFeeExcludedFromFiat: true,
49
+ messenger,
50
+ });
42
51
  messenger.call('TransactionPayController:updateFiatPayment', {
43
52
  callback: (fiatPayment) => {
44
53
  fiatPayment.rampsQuote = fiatQuote;
@@ -56,6 +65,7 @@ export async function getDirectMusdFiatQuote({ amountFiat, fiatPaymentMethod, me
56
65
  fiatQuote,
57
66
  messenger,
58
67
  moneyAccountAddress,
68
+ nativeRampsFee,
59
69
  requiredToken,
60
70
  });
61
71
  }
@@ -107,7 +117,7 @@ export async function submitDirectMusdAfterFiatCompletion({ order, request, }) {
107
117
  throw prefixError(error, DIRECT_MUSD_ERROR_PREFIX);
108
118
  }
109
119
  }
110
- function combineDirectMusdFiatQuote({ amountFiat, fiatQuote, messenger, moneyAccountAddress, requiredToken, }) {
120
+ function combineDirectMusdFiatQuote({ amountFiat, fiatQuote, messenger, moneyAccountAddress, nativeRampsFee, requiredToken, }) {
111
121
  const tokenInfo = getTokenInfo(messenger, MUSD_MONAD_FIAT_ASSET.address, MUSD_MONAD_FIAT_ASSET.chainId);
112
122
  if (!tokenInfo) {
113
123
  throw new Error('Unable to resolve mUSD token info for direct fiat quote');
@@ -116,16 +126,18 @@ function combineDirectMusdFiatQuote({ amountFiat, fiatQuote, messenger, moneyAcc
116
126
  cryptoAmount: fiatQuote.quote.amountOut,
117
127
  decimals: tokenInfo.decimals,
118
128
  });
119
- // `getQuoteWithFees` already reconciled the fee split to the resolved
120
- // provider (for Transak Native, the native total split across provider and
121
- // network), so the provider/network fields can be mapped straight into the
122
- // fee buckets.
123
- const rampsProviderFee = getSafeFee(fiatQuote.quote.providerFee).toString(10);
124
- const rampsNetworkFee = getSafeFee(fiatQuote.quote.networkFee).toString(10);
129
+ // Transak Native returns a single total fee, so the aggregator's separate
130
+ // provider/network split collapses: the whole native fee sits in the provider
131
+ // bucket and the source-network fee is zero. The `providerFiat` total stays
132
+ // correct either way.
133
+ const rampsProviderFee = (nativeRampsFee ?? getSafeFee(fiatQuote.quote.providerFee)).toString(10);
134
+ const rampsNetworkFee = nativeRampsFee
135
+ ? '0'
136
+ : getSafeFee(fiatQuote.quote.networkFee).toString(10);
125
137
  const rampsTotalFee = new BigNumber(rampsProviderFee)
126
138
  .plus(rampsNetworkFee)
127
139
  .toString(10);
128
- const targetAmountFiat = getDirectMusdTargetAmountFiat(fiatQuote, amountFiat);
140
+ const targetAmountFiat = getDirectMusdTargetAmountFiat(fiatQuote);
129
141
  const sourceAmountHuman = new BigNumber(sourceAmountRaw)
130
142
  .shiftedBy(-tokenInfo.decimals)
131
143
  .toString(10);
@@ -182,23 +194,12 @@ function combineDirectMusdFiatQuote({ amountFiat, fiatQuote, messenger, moneyAcc
182
194
  targetAmount: { fiat: targetAmountFiat, usd: targetAmountFiat },
183
195
  };
184
196
  }
185
- /**
186
- * Resolves the fiat value of the received mUSD for a direct deposit quote.
187
- *
188
- * Prefers the quote's `amountOutInFiat`. When that is missing, it falls back to
189
- * the entered fiat amount rather than `amountOut`, which is a crypto amount and
190
- * would otherwise put crypto units into a fiat field.
191
- *
192
- * @param fiatQuote - The resolved ramps quote.
193
- * @param amountFiat - The entered fiat amount, used as the fallback.
194
- * @returns The target amount in fiat.
195
- */
196
- function getDirectMusdTargetAmountFiat(fiatQuote, amountFiat) {
197
+ function getDirectMusdTargetAmountFiat(fiatQuote) {
197
198
  const amountOutInFiat = new BigNumber(fiatQuote.quote.amountOutInFiat ?? NaN);
198
199
  if (amountOutInFiat.isFinite() && amountOutInFiat.isGreaterThanOrEqualTo(0)) {
199
200
  return amountOutInFiat.toString(10);
200
201
  }
201
- return amountFiat;
202
+ return new BigNumber(fiatQuote.quote.amountOut).toString(10);
202
203
  }
203
204
  function getSafeFee(value) {
204
205
  const fee = new BigNumber(value ?? 0);
@@ -1 +1 @@
1
- {"version":3,"file":"fiat-direct-musd.js","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-direct-musd.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAQhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EACL,aAAa,EACb,uCAAuC,EACvC,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAClE,MAAM,wBAAwB,GAAG,eAAe,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,aAAa,GAQd;IACC,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,CAAC,QAAQ,C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,CAAC,GAAG;QACL,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import type {\n Quote as RampsQuote,\n RampsOrder,\n} from '@metamask/ramps-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { TransactionPayStrategy } from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyExecuteRequest,\n PayStrategyGetQuotesRequest,\n TransactionFiatPayment,\n TransactionPayRequiredToken,\n TransactionPayQuote,\n} from '../../types.js';\nimport { prefixError } from '../../utils/error-prefix.js';\nimport { getFiatVaultDisabled } from '../../utils/feature-flags.js';\nimport { submitMoneyAccountVaultDeposit } from '../../utils/ma-vault-deposit.js';\nimport { buildCaipAssetType, getTokenInfo } from '../../utils/token.js';\nimport { MUSD_MONAD_FIAT_ASSET } from './constants.js';\nimport type { FiatQuote } from './types.js';\nimport {\n getRampsQuote,\n getRawSourceAmountFromOrderCryptoAmount,\n resolveSourceAmountRaw,\n validateOrderAsset,\n} from './utils.js';\n\nconst log = createModuleLogger(projectLogger, 'fiat-direct-musd');\nconst DIRECT_MUSD_ERROR_PREFIX = 'Direct mUSD: ';\n\n/**\n * Returns a direct mUSD fiat quote to the Money Account.\n *\n * @param options - Direct quote options.\n * @param options.amountFiat - Fiat amount entered by the user.\n * @param options.fiatPaymentMethod - Selected fiat payment method.\n * @param options.messenger - Controller messenger.\n * @param options.moneyAccountAddress - Money Account receiving the on-ramped mUSD.\n * @param options.requiredToken - Required token from the original Money Account transaction.\n * @param options.transactionId - Transaction ID for state updates and logs.\n * @returns Direct mUSD Fiat quote, or undefined when unavailable.\n */\nexport async function getDirectMusdFiatQuote({\n amountFiat,\n fiatPaymentMethod,\n messenger,\n moneyAccountAddress,\n requiredToken,\n transactionId,\n}: {\n amountFiat: string;\n fiatPaymentMethod: string;\n messenger: PayStrategyGetQuotesRequest['messenger'];\n moneyAccountAddress: Hex;\n requiredToken: TransactionPayRequiredToken;\n transactionId: string;\n}): Promise<TransactionPayQuote<FiatQuote> | undefined> {\n try {\n const adjustedAmount = Number(amountFiat);\n\n if (!Number.isFinite(adjustedAmount) || adjustedAmount <= 0) {\n throw new Error('Invalid fiat amount for direct mUSD quote');\n }\n\n // `getRampsQuote` requests `getQuoteWithFees`, so a Transak Native quote\n // already carries the native fee (fee-on-top for direct mUSD) in its\n // provider/network fee fields.\n const fiatQuote = await getRampsQuote({\n adjustedAmount,\n errorMessage: 'No matching ramps quote found for direct mUSD provider',\n fiatAsset: MUSD_MONAD_FIAT_ASSET,\n fiatPaymentMethod,\n messenger,\n walletAddress: moneyAccountAddress,\n });\n\n messenger.call('TransactionPayController:updateFiatPayment', {\n callback: (fiatPayment: TransactionFiatPayment) => {\n fiatPayment.rampsQuote = fiatQuote;\n fiatPayment.caipAssetId = buildCaipAssetType(\n MUSD_MONAD_FIAT_ASSET.chainId,\n MUSD_MONAD_FIAT_ASSET.address,\n );\n },\n transactionId,\n });\n\n log('Direct mUSD fiat quote flow', {\n amountFiat,\n moneyAccountAddress,\n transactionId,\n });\n\n return combineDirectMusdFiatQuote({\n amountFiat,\n fiatQuote,\n messenger,\n moneyAccountAddress,\n requiredToken,\n });\n } catch (error) {\n log('Direct mUSD fiat quote failed', { error, transactionId });\n return undefined;\n }\n}\n\n/**\n * Detects a direct mUSD Money Account quote from its stored request marker.\n *\n * @param quote - Quote to inspect.\n * @returns True when the quote originated from the direct mUSD fiat path.\n */\nexport function isDirectMusdMoneyAccountQuote(\n quote: Pick<TransactionPayQuote<unknown>, 'request'> | undefined,\n): boolean {\n return quote?.request.isDirectMusdMoneyAccount === true;\n}\n\n/**\n * Submits the direct mUSD post-Ramp path after fiat settlement.\n *\n * @param options - Submit options.\n * @param options.order - Completed fiat order.\n * @param options.request - Strategy execute request.\n * @returns Hash of the submitted direct mUSD transaction, if available.\n */\nexport async function submitDirectMusdAfterFiatCompletion({\n order,\n request,\n}: {\n order: RampsOrder;\n request: PayStrategyExecuteRequest<FiatQuote>;\n}): Promise<{ transactionHash?: Hex }> {\n const { messenger, transaction } = request;\n\n try {\n validateOrderAsset({\n expectedAsset: MUSD_MONAD_FIAT_ASSET,\n orderCrypto: order.cryptoCurrency,\n transactionId: transaction.id,\n });\n\n const { amountRaw: sourceAmountRaw, fromBlock } =\n await resolveSourceAmountRaw({\n messenger,\n order,\n fiatAsset: MUSD_MONAD_FIAT_ASSET,\n walletAddress: transaction.txParams.from as Hex,\n });\n\n return await submitMoneyAccountVaultDeposit({\n fromBlock,\n messenger,\n sourceAmountRaw,\n transaction,\n vaultDisabled: getFiatVaultDisabled(messenger),\n });\n } catch (error) {\n throw prefixError(error, DIRECT_MUSD_ERROR_PREFIX);\n }\n}\n\nfunction combineDirectMusdFiatQuote({\n amountFiat,\n fiatQuote,\n messenger,\n moneyAccountAddress,\n requiredToken,\n}: {\n amountFiat: string;\n fiatQuote: RampsQuote;\n messenger: PayStrategyGetQuotesRequest['messenger'];\n moneyAccountAddress: Hex;\n requiredToken: TransactionPayRequiredToken;\n}): TransactionPayQuote<FiatQuote> {\n const tokenInfo = getTokenInfo(\n messenger,\n MUSD_MONAD_FIAT_ASSET.address,\n MUSD_MONAD_FIAT_ASSET.chainId,\n );\n\n if (!tokenInfo) {\n throw new Error('Unable to resolve mUSD token info for direct fiat quote');\n }\n\n const sourceAmountRaw = getRawSourceAmountFromOrderCryptoAmount({\n cryptoAmount: fiatQuote.quote.amountOut,\n decimals: tokenInfo.decimals,\n });\n // `getQuoteWithFees` already reconciled the fee split to the resolved\n // provider (for Transak Native, the native total split across provider and\n // network), so the provider/network fields can be mapped straight into the\n // fee buckets.\n const rampsProviderFee = getSafeFee(fiatQuote.quote.providerFee).toString(10);\n const rampsNetworkFee = getSafeFee(fiatQuote.quote.networkFee).toString(10);\n const rampsTotalFee = new BigNumber(rampsProviderFee)\n .plus(rampsNetworkFee)\n .toString(10);\n const targetAmountFiat = getDirectMusdTargetAmountFiat(fiatQuote, amountFiat);\n const sourceAmountHuman = new BigNumber(sourceAmountRaw)\n .shiftedBy(-tokenInfo.decimals)\n .toString(10);\n\n return {\n // Direct mUSD is fee-on-top: the fee is added to the entered amount, so the\n // fees are NOT already inside the source amount and the total becomes\n // amount + fees (see calculateTotals).\n areFeesIncludedInSourceAmount: false,\n dust: { fiat: '0', usd: '0' },\n estimatedDuration: 0,\n fees: {\n metaMask: { fiat: '0', usd: '0' },\n provider: { fiat: rampsProviderFee, usd: rampsProviderFee },\n providerFiat: { fiat: rampsTotalFee, usd: rampsTotalFee },\n sourceNetwork: {\n estimate: {\n fiat: rampsNetworkFee,\n human: '0',\n raw: '0',\n usd: rampsNetworkFee,\n },\n max: {\n fiat: rampsNetworkFee,\n human: '0',\n raw: '0',\n usd: rampsNetworkFee,\n },\n },\n targetNetwork: { fiat: '0', usd: '0' },\n },\n original: {\n rampsQuote: fiatQuote,\n relayQuote: undefined,\n },\n request: {\n from: moneyAccountAddress,\n isDirectMusdMoneyAccount: true,\n recipient: moneyAccountAddress,\n sourceBalanceRaw: sourceAmountRaw,\n sourceChainId: MUSD_MONAD_FIAT_ASSET.chainId,\n sourceTokenAddress: MUSD_MONAD_FIAT_ASSET.address,\n sourceTokenAmount: sourceAmountRaw,\n targetAmountMinimum: sourceAmountRaw,\n targetChainId: requiredToken.chainId,\n targetTokenAddress: requiredToken.address,\n },\n sourceAmount: {\n fiat: amountFiat,\n human: sourceAmountHuman,\n raw: sourceAmountRaw,\n usd: amountFiat,\n },\n strategy: TransactionPayStrategy.Fiat,\n targetAmount: { fiat: targetAmountFiat, usd: targetAmountFiat },\n };\n}\n\n/**\n * Resolves the fiat value of the received mUSD for a direct deposit quote.\n *\n * Prefers the quote's `amountOutInFiat`. When that is missing, it falls back to\n * the entered fiat amount rather than `amountOut`, which is a crypto amount and\n * would otherwise put crypto units into a fiat field.\n *\n * @param fiatQuote - The resolved ramps quote.\n * @param amountFiat - The entered fiat amount, used as the fallback.\n * @returns The target amount in fiat.\n */\nfunction getDirectMusdTargetAmountFiat(\n fiatQuote: RampsQuote,\n amountFiat: string,\n): string {\n const amountOutInFiat = new BigNumber(fiatQuote.quote.amountOutInFiat ?? NaN);\n if (amountOutInFiat.isFinite() && amountOutInFiat.isGreaterThanOrEqualTo(0)) {\n return amountOutInFiat.toString(10);\n }\n\n return amountFiat;\n}\n\nfunction getSafeFee(value: BigNumber.Value | undefined): BigNumber {\n const fee = new BigNumber(value ?? 0);\n return fee.isFinite() && fee.isGreaterThanOrEqualTo(0)\n ? fee\n : new BigNumber(0);\n}\n"]}
1
+ {"version":3,"file":"fiat-direct-musd.js","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-direct-musd.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAQhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,uCAAuC,EACvC,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAClE,MAAM,wBAAwB,GAAG,eAAe,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,EAC3C,U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AAG,CAAC,CAAC;IAC9E,IAAI,eAAe,CAAC,QAAQ,EAAE,IAAI,eAAe,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,OAAO,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,UAAU,CAAC,KAAkC;IACpD,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import type {\n Quote as RampsQuote,\n RampsOrder,\n} from '@metamask/ramps-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport { TransactionPayStrategy } from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyExecuteRequest,\n PayStrategyGetQuotesRequest,\n TransactionFiatPayment,\n TransactionPayRequiredToken,\n TransactionPayQuote,\n} from '../../types.js';\nimport { prefixError } from '../../utils/error-prefix.js';\nimport { getFiatVaultDisabled } from '../../utils/feature-flags.js';\nimport { submitMoneyAccountVaultDeposit } from '../../utils/ma-vault-deposit.js';\nimport { buildCaipAssetType, getTokenInfo } from '../../utils/token.js';\nimport { MUSD_MONAD_FIAT_ASSET } from './constants.js';\nimport type { FiatQuote } from './types.js';\nimport {\n getNativeTransakRampsFee,\n getRampsQuote,\n getRawSourceAmountFromOrderCryptoAmount,\n resolveSourceAmountRaw,\n validateOrderAsset,\n} from './utils.js';\n\nconst log = createModuleLogger(projectLogger, 'fiat-direct-musd');\nconst DIRECT_MUSD_ERROR_PREFIX = 'Direct mUSD: ';\n\n/**\n * Returns a direct mUSD fiat quote to the Money Account.\n *\n * @param options - Direct quote options.\n * @param options.amountFiat - Fiat amount entered by the user.\n * @param options.fiatPaymentMethod - Selected fiat payment method.\n * @param options.messenger - Controller messenger.\n * @param options.moneyAccountAddress - Money Account receiving the on-ramped mUSD.\n * @param options.requiredToken - Required token from the original Money Account transaction.\n * @param options.transactionId - Transaction ID for state updates and logs.\n * @returns Direct mUSD Fiat quote, or undefined when unavailable.\n */\nexport async function getDirectMusdFiatQuote({\n amountFiat,\n fiatPaymentMethod,\n messenger,\n moneyAccountAddress,\n requiredToken,\n transactionId,\n}: {\n amountFiat: string;\n fiatPaymentMethod: string;\n messenger: PayStrategyGetQuotesRequest['messenger'];\n moneyAccountAddress: Hex;\n requiredToken: TransactionPayRequiredToken;\n transactionId: string;\n}): Promise<TransactionPayQuote<FiatQuote> | undefined> {\n try {\n const adjustedAmount = Number(amountFiat);\n\n if (!Number.isFinite(adjustedAmount) || adjustedAmount <= 0) {\n throw new Error('Invalid fiat amount for direct mUSD quote');\n }\n\n const fiatQuote = await getRampsQuote({\n adjustedAmount,\n errorMessage: 'No matching ramps quote found for direct mUSD provider',\n fiatAsset: MUSD_MONAD_FIAT_ASSET,\n fiatPaymentMethod,\n messenger,\n walletAddress: moneyAccountAddress,\n });\n\n // When Transak Native is the resolved provider, prefer its own quote's fee\n // so the estimate matches what Transak Native will charge. Direct mUSD is\n // fee-on-top (the fee is added to the entered amount), so request the native\n // quote in that mode.\n const nativeRampsFee = await getNativeTransakRampsFee({\n adjustedAmount,\n fiatAsset: MUSD_MONAD_FIAT_ASSET,\n fiatPaymentMethod,\n fiatQuote,\n isFeeExcludedFromFiat: true,\n messenger,\n });\n\n messenger.call('TransactionPayController:updateFiatPayment', {\n callback: (fiatPayment: TransactionFiatPayment) => {\n fiatPayment.rampsQuote = fiatQuote;\n fiatPayment.caipAssetId = buildCaipAssetType(\n MUSD_MONAD_FIAT_ASSET.chainId,\n MUSD_MONAD_FIAT_ASSET.address,\n );\n },\n transactionId,\n });\n\n log('Direct mUSD fiat quote flow', {\n amountFiat,\n moneyAccountAddress,\n transactionId,\n });\n\n return combineDirectMusdFiatQuote({\n amountFiat,\n fiatQuote,\n messenger,\n moneyAccountAddress,\n nativeRampsFee,\n requiredToken,\n });\n } catch (error) {\n log('Direct mUSD fiat quote failed', { error, transactionId });\n return undefined;\n }\n}\n\n/**\n * Detects a direct mUSD Money Account quote from its stored request marker.\n *\n * @param quote - Quote to inspect.\n * @returns True when the quote originated from the direct mUSD fiat path.\n */\nexport function isDirectMusdMoneyAccountQuote(\n quote: Pick<TransactionPayQuote<unknown>, 'request'> | undefined,\n): boolean {\n return quote?.request.isDirectMusdMoneyAccount === true;\n}\n\n/**\n * Submits the direct mUSD post-Ramp path after fiat settlement.\n *\n * @param options - Submit options.\n * @param options.order - Completed fiat order.\n * @param options.request - Strategy execute request.\n * @returns Hash of the submitted direct mUSD transaction, if available.\n */\nexport async function submitDirectMusdAfterFiatCompletion({\n order,\n request,\n}: {\n order: RampsOrder;\n request: PayStrategyExecuteRequest<FiatQuote>;\n}): Promise<{ transactionHash?: Hex }> {\n const { messenger, transaction } = request;\n\n try {\n validateOrderAsset({\n expectedAsset: MUSD_MONAD_FIAT_ASSET,\n orderCrypto: order.cryptoCurrency,\n transactionId: transaction.id,\n });\n\n const { amountRaw: sourceAmountRaw, fromBlock } =\n await resolveSourceAmountRaw({\n messenger,\n order,\n fiatAsset: MUSD_MONAD_FIAT_ASSET,\n walletAddress: transaction.txParams.from as Hex,\n });\n\n return await submitMoneyAccountVaultDeposit({\n fromBlock,\n messenger,\n sourceAmountRaw,\n transaction,\n vaultDisabled: getFiatVaultDisabled(messenger),\n });\n } catch (error) {\n throw prefixError(error, DIRECT_MUSD_ERROR_PREFIX);\n }\n}\n\nfunction combineDirectMusdFiatQuote({\n amountFiat,\n fiatQuote,\n messenger,\n moneyAccountAddress,\n nativeRampsFee,\n requiredToken,\n}: {\n amountFiat: string;\n fiatQuote: RampsQuote;\n messenger: PayStrategyGetQuotesRequest['messenger'];\n moneyAccountAddress: Hex;\n nativeRampsFee: BigNumber | null;\n requiredToken: TransactionPayRequiredToken;\n}): TransactionPayQuote<FiatQuote> {\n const tokenInfo = getTokenInfo(\n messenger,\n MUSD_MONAD_FIAT_ASSET.address,\n MUSD_MONAD_FIAT_ASSET.chainId,\n );\n\n if (!tokenInfo) {\n throw new Error('Unable to resolve mUSD token info for direct fiat quote');\n }\n\n const sourceAmountRaw = getRawSourceAmountFromOrderCryptoAmount({\n cryptoAmount: fiatQuote.quote.amountOut,\n decimals: tokenInfo.decimals,\n });\n // Transak Native returns a single total fee, so the aggregator's separate\n // provider/network split collapses: the whole native fee sits in the provider\n // bucket and the source-network fee is zero. The `providerFiat` total stays\n // correct either way.\n const rampsProviderFee = (\n nativeRampsFee ?? getSafeFee(fiatQuote.quote.providerFee)\n ).toString(10);\n const rampsNetworkFee = nativeRampsFee\n ? '0'\n : getSafeFee(fiatQuote.quote.networkFee).toString(10);\n const rampsTotalFee = new BigNumber(rampsProviderFee)\n .plus(rampsNetworkFee)\n .toString(10);\n const targetAmountFiat = getDirectMusdTargetAmountFiat(fiatQuote);\n const sourceAmountHuman = new BigNumber(sourceAmountRaw)\n .shiftedBy(-tokenInfo.decimals)\n .toString(10);\n\n return {\n // Direct mUSD is fee-on-top: the fee is added to the entered amount, so the\n // fees are NOT already inside the source amount and the total becomes\n // amount + fees (see calculateTotals).\n areFeesIncludedInSourceAmount: false,\n dust: { fiat: '0', usd: '0' },\n estimatedDuration: 0,\n fees: {\n metaMask: { fiat: '0', usd: '0' },\n provider: { fiat: rampsProviderFee, usd: rampsProviderFee },\n providerFiat: { fiat: rampsTotalFee, usd: rampsTotalFee },\n sourceNetwork: {\n estimate: {\n fiat: rampsNetworkFee,\n human: '0',\n raw: '0',\n usd: rampsNetworkFee,\n },\n max: {\n fiat: rampsNetworkFee,\n human: '0',\n raw: '0',\n usd: rampsNetworkFee,\n },\n },\n targetNetwork: { fiat: '0', usd: '0' },\n },\n original: {\n rampsQuote: fiatQuote,\n relayQuote: undefined,\n },\n request: {\n from: moneyAccountAddress,\n isDirectMusdMoneyAccount: true,\n recipient: moneyAccountAddress,\n sourceBalanceRaw: sourceAmountRaw,\n sourceChainId: MUSD_MONAD_FIAT_ASSET.chainId,\n sourceTokenAddress: MUSD_MONAD_FIAT_ASSET.address,\n sourceTokenAmount: sourceAmountRaw,\n targetAmountMinimum: sourceAmountRaw,\n targetChainId: requiredToken.chainId,\n targetTokenAddress: requiredToken.address,\n },\n sourceAmount: {\n fiat: amountFiat,\n human: sourceAmountHuman,\n raw: sourceAmountRaw,\n usd: amountFiat,\n },\n strategy: TransactionPayStrategy.Fiat,\n targetAmount: { fiat: targetAmountFiat, usd: targetAmountFiat },\n };\n}\n\nfunction getDirectMusdTargetAmountFiat(fiatQuote: RampsQuote): string {\n const amountOutInFiat = new BigNumber(fiatQuote.quote.amountOutInFiat ?? NaN);\n if (amountOutInFiat.isFinite() && amountOutInFiat.isGreaterThanOrEqualTo(0)) {\n return amountOutInFiat.toString(10);\n }\n\n return new BigNumber(fiatQuote.quote.amountOut).toString(10);\n}\n\nfunction getSafeFee(value: BigNumber.Value | undefined): BigNumber {\n const fee = new BigNumber(value ?? 0);\n return fee.isFinite() && fee.isGreaterThanOrEqualTo(0)\n ? fee\n : new BigNumber(0);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fiat-quotes.d.ts","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-quotes.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,2BAA2B,EAI3B,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiB5C;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CA0C3C"}
1
+ {"version":3,"file":"fiat-quotes.d.ts","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-quotes.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,2BAA2B,EAI3B,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAkB5C;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CA0C3C"}
@@ -6,7 +6,7 @@ import { getDirectMoneyMusdEnabled } from '../../utils/feature-flags.js';
6
6
  import { buildCaipAssetType, computeRawFromFiatAmount, getTokenFiatRate, getTokenInfo, } from '../../utils/token.js';
7
7
  import { getRelayQuotes } from '../relay/relay-quotes.js';
8
8
  import { getDirectMusdFiatQuote } from './fiat-direct-musd.js';
9
- import { deriveFiatAssetForFiatPayment, getRampsQuote, isMoneyAccountDepositTransaction, } from './utils.js';
9
+ import { deriveFiatAssetForFiatPayment, getNativeTransakRampsFee, getRampsQuote, isMoneyAccountDepositTransaction, } from './utils.js';
10
10
  const log = createModuleLogger(projectLogger, 'fiat-strategy');
11
11
  /**
12
12
  * Fetches MM Pay fiat strategy quotes using a relay-first estimation flow.
@@ -109,6 +109,17 @@ async function executeFiatQuotePipeline(request, options) {
109
109
  messenger,
110
110
  walletAddress: rampsWalletAddress,
111
111
  });
112
+ // When Transak Native is the resolved provider, prefer its own quote's fee
113
+ // so the estimate matches what Transak Native will charge. The relay path
114
+ // stays fee-on-top, so request the native quote in the same mode.
115
+ const nativeRampsFee = await getNativeTransakRampsFee({
116
+ adjustedAmount,
117
+ fiatAsset,
118
+ fiatPaymentMethod,
119
+ fiatQuote,
120
+ isFeeExcludedFromFiat: true,
121
+ messenger,
122
+ });
112
123
  messenger.call('TransactionPayController:updateFiatPayment', {
113
124
  callback: (fiatPayment) => {
114
125
  fiatPayment.rampsQuote = fiatQuote;
@@ -121,6 +132,7 @@ async function executeFiatQuotePipeline(request, options) {
121
132
  adjustedAmountFiat: adjustedAmountFiat.toString(10),
122
133
  amountFiat,
123
134
  fiatQuote,
135
+ nativeRampsFee,
124
136
  relayQuote,
125
137
  }),
126
138
  ];
@@ -170,8 +182,8 @@ function buildRelayRequestFromAmountFiat({ amountFiat, fiatAsset, messenger, req
170
182
  * @param params - Combined quote inputs.
171
183
  * @param params.adjustedAmountFiat - Fiat amount sent to ramps after adding relay fee estimate.
172
184
  * @param params.amountFiat - User-entered fiat amount.
173
- * @param params.fiatQuote - Selected ramps quote, with fees already reconciled
174
- * to the resolved provider by `RampsController:getQuoteWithFees`.
185
+ * @param params.fiatQuote - Selected ramps quote.
186
+ * @param params.nativeRampsFee - Native Transak fee to use in place of the aggregator ramps fee, or null.
175
187
  * @param params.relayQuote - Estimated relay quote.
176
188
  * @returns A single fiat strategy quote with split fee buckets.
177
189
  * @remarks
@@ -186,8 +198,8 @@ function buildRelayRequestFromAmountFiat({ amountFiat, fiatAsset, messenger, req
186
198
  * Consumed by UI transaction fee row and tooltip MetaMask fee.
187
199
  * - `totals.total` should represent Amount + Transaction Fee using the totals pipeline.
188
200
  */
189
- function combineQuotes({ adjustedAmountFiat, amountFiat, fiatQuote, relayQuote, }) {
190
- const rampsProviderFee = getRampsProviderFee(fiatQuote);
201
+ function combineQuotes({ adjustedAmountFiat, amountFiat, fiatQuote, nativeRampsFee, relayQuote, }) {
202
+ const rampsProviderFee = nativeRampsFee ?? getRampsProviderFee(fiatQuote);
191
203
  const totalProviderFee = new BigNumber(relayQuote.fees.provider.usd)
192
204
  .plus(rampsProviderFee)
193
205
  .toString(10);
@@ -1 +1 @@
1
- {"version":3,"file":"fiat-quotes.js","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-quotes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAA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C,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;SACvC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,cAAc,CAAC,EACtB,kBAAkB,EAClB,UAAU,GAIX;IACC,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { Quote as RampsQuote } from '@metamask/ramps-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n NATIVE_TOKEN_ADDRESS,\n TransactionPayStrategy,\n} from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionFiatPayment,\n TransactionPayRequiredToken,\n TransactionPayQuote,\n} from '../../types.js';\nimport { getDirectMoneyMusdEnabled } from '../../utils/feature-flags.js';\nimport {\n buildCaipAssetType,\n computeRawFromFiatAmount,\n getTokenFiatRate,\n getTokenInfo,\n} from '../../utils/token.js';\nimport { getRelayQuotes } from '../relay/relay-quotes.js';\nimport type { RelayQuote } from '../relay/types.js';\nimport type { TransactionPayFiatAsset } from './constants.js';\nimport { getDirectMusdFiatQuote } from './fiat-direct-musd.js';\nimport type { FiatQuote } from './types.js';\nimport {\n deriveFiatAssetForFiatPayment,\n getRampsQuote,\n isMoneyAccountDepositTransaction,\n} from './utils.js';\n\nconst log = createModuleLogger(projectLogger, 'fiat-strategy');\n\ntype FiatQuotePipelineOptions = {\n amountFiat: string;\n fiatAsset: TransactionPayFiatAsset;\n fiatPaymentMethod: string;\n rampsWalletAddress: Hex;\n requiredTokens: TransactionPayRequiredToken[];\n};\n\n/**\n * Fetches MM Pay fiat strategy quotes using a relay-first estimation flow.\n *\n * When the direct-to-mUSD flag is enabled and the transaction is a Money\n * Account deposit, uses direct mUSD params (asset, wallet, recipient).\n * Otherwise, uses the standard ETH flow.\n *\n * @param request - Strategy quotes request.\n * @returns A single combined fiat strategy quote, or an empty array when inputs/quotes are unavailable.\n */\nexport async function getFiatQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<FiatQuote>[]> {\n const { messenger, transaction } = request;\n\n const state = messenger.call('TransactionPayController:getState');\n const transactionData = state.transactionData[transaction.id];\n const amountFiat = transactionData?.fiatPayment?.amountFiat;\n const requiredTokens = transactionData?.tokens ?? [];\n\n if (\n !amountFiat ||\n !request.fiatPaymentMethod ||\n requiredTokens.length !== 1\n ) {\n return [];\n }\n\n const useDirectMusd =\n getDirectMoneyMusdEnabled(messenger) &&\n isMoneyAccountDepositTransaction(transaction);\n\n if (useDirectMusd) {\n const requiredToken = requiredTokens[0];\n\n const directQuote = await getDirectMusdFiatQuote({\n amountFiat,\n fiatPaymentMethod: request.fiatPaymentMethod,\n messenger,\n moneyAccountAddress: transaction.txParams.from as Hex,\n requiredToken,\n transactionId: transaction.id,\n });\n\n return directQuote ? [directQuote] : [];\n }\n\n return executeFiatQuotePipeline(request, {\n amountFiat,\n fiatAsset: deriveFiatAssetForFiatPayment(transaction, messenger),\n fiatPaymentMethod: request.fiatPaymentMethod,\n rampsWalletAddress: request.from,\n requiredTokens,\n });\n}\n\nasync function executeFiatQuotePipeline(\n request: PayStrategyGetQuotesRequest,\n options: FiatQuotePipelineOptions,\n): Promise<TransactionPayQuote<FiatQuote>[]> {\n const {\n accountSupports7702,\n from: walletAddress,\n messenger,\n transaction,\n } = request;\n const {\n amountFiat,\n fiatAsset,\n fiatPaymentMethod,\n rampsWalletAddress,\n requiredTokens,\n } = options;\n const transactionId = transaction.id;\n\n try {\n const requiredToken = requiredTokens[0];\n\n const relayRequest = buildRelayRequestFromAmountFiat({\n amountFiat,\n fiatAsset,\n messenger,\n requiredToken,\n walletAddress,\n });\n\n if (!relayRequest) {\n throw new Error('Failed to build relay request from fiat amount');\n }\n\n const relayQuotes = await getRelayQuotes({\n accountSupports7702,\n from: walletAddress,\n messenger,\n requests: [relayRequest],\n transaction,\n });\n\n const relayQuote = relayQuotes[0];\n if (!relayQuote) {\n throw new Error('No relay quote available for fiat estimation');\n }\n\n const isSourceNative =\n fiatAsset.address.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase();\n const gasDeductedFromSource =\n isSourceNative || relayQuote.fees.isSourceGasFeeToken === true;\n\n const relayTotalFeeUsd = gasDeductedFromSource\n ? getRelayTotalFeeUsd(relayQuote)\n : getNonGasRelayFeeUsd(relayQuote);\n const adjustedAmountFiat = new BigNumber(amountFiat).plus(relayTotalFeeUsd);\n\n if (\n !adjustedAmountFiat.isFinite() ||\n !adjustedAmountFiat.gt(0) ||\n !relayTotalFeeUsd.isFinite() ||\n !relayTotalFeeUsd.gte(0)\n ) {\n throw new Error('Invalid fiat amount after relay fee adjustment');\n }\n\n const adjustedAmount = adjustedAmountFiat.toNumber();\n\n if (!Number.isFinite(adjustedAmount) || adjustedAmount <= 0) {\n throw new Error('Invalid fiat amount after relay fee adjustment');\n }\n\n log('Fiat quote flow', {\n adjustedAmountFiat: adjustedAmountFiat.toString(10),\n amountFiat,\n rampsWalletAddress,\n relayTotalFeeUsd: relayTotalFeeUsd.toString(10),\n sourceAmountRaw: relayRequest.sourceTokenAmount,\n transactionId,\n });\n\n const fiatQuote = await getRampsQuote({\n adjustedAmount,\n fiatAsset,\n fiatPaymentMethod,\n messenger,\n walletAddress: rampsWalletAddress,\n });\n\n messenger.call('TransactionPayController:updateFiatPayment', {\n callback: (fiatPayment: TransactionFiatPayment) => {\n fiatPayment.rampsQuote = fiatQuote;\n fiatPayment.caipAssetId = buildCaipAssetType(\n fiatAsset.chainId,\n fiatAsset.address,\n );\n },\n transactionId,\n });\n\n return [\n combineQuotes({\n adjustedAmountFiat: adjustedAmountFiat.toString(10),\n amountFiat,\n fiatQuote,\n relayQuote,\n }),\n ];\n } catch (error) {\n log('Failed to fetch fiat quotes', { error, transactionId });\n\n messenger.call('TransactionPayController:updateFiatPayment', {\n callback: (fiatPayment) => {\n fiatPayment.rampsQuote = undefined;\n },\n transactionId,\n });\n }\n\n return [];\n}\n\nfunction buildRelayRequestFromAmountFiat({\n amountFiat,\n fiatAsset,\n messenger,\n requiredToken,\n walletAddress,\n}: {\n amountFiat: string;\n fiatAsset: {\n address: Hex;\n chainId: Hex;\n };\n messenger: PayStrategyGetQuotesRequest['messenger'];\n requiredToken: TransactionPayRequiredToken;\n walletAddress: Hex;\n}): QuoteRequest | undefined {\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n fiatAsset.address,\n fiatAsset.chainId,\n );\n\n if (!sourceFiatRate) {\n return undefined;\n }\n\n const tokenInfo = getTokenInfo(\n messenger,\n fiatAsset.address,\n fiatAsset.chainId,\n );\n\n if (!tokenInfo) {\n return undefined;\n }\n\n const sourceAmountRaw = computeRawFromFiatAmount(\n amountFiat,\n tokenInfo.decimals,\n sourceFiatRate.usdRate,\n );\n\n if (!sourceAmountRaw) {\n return undefined;\n }\n\n return {\n from: walletAddress,\n // Force EXACT_INPUT mode: source amount is pre-calculated from the fiat\n // amount, so the relay should treat it as a fixed input rather than\n // computing it from the target.\n isPostQuote: true,\n sourceBalanceRaw: sourceAmountRaw,\n sourceChainId: fiatAsset.chainId,\n sourceTokenAddress: fiatAsset.address,\n sourceTokenAmount: sourceAmountRaw,\n targetAmountMinimum: requiredToken.amountRaw,\n targetChainId: requiredToken.chainId,\n targetTokenAddress: requiredToken.address,\n };\n}\n\n/**\n * Combines fiat and relay legs into a single MM Pay fiat strategy quote.\n *\n * @param params - Combined quote inputs.\n * @param params.adjustedAmountFiat - Fiat amount sent to ramps after adding relay fee estimate.\n * @param params.amountFiat - User-entered fiat amount.\n * @param params.fiatQuote - Selected ramps quote, with fees already reconciled\n * to the resolved provider by `RampsController:getQuoteWithFees`.\n * @param params.relayQuote - Estimated relay quote.\n * @returns A single fiat strategy quote with split fee buckets.\n * @remarks\n * Fee mapping contract for MM Pay Fiat strategy:\n * - `fees.provider`: Total provider fee (relay provider/swap fee + ramps provider/network fee).\n * Consumed by UI transaction fee row and tooltip provider fee.\n * - `fees.providerFiat`: Fiat on-ramp provider fees only (`providerFee + networkFee` from ramps quote).\n * Optional breakdown; client can derive relay portion via `provider - providerFiat`.\n * - `fees.sourceNetwork` / `fees.targetNetwork`: Relay settlement network fees.\n * Consumed by UI transaction fee row and tooltip network fee.\n * - `fees.metaMask`: MM Pay fee (currently 100 bps over `amountFiat + adjustedAmountFiat`).\n * Consumed by UI transaction fee row and tooltip MetaMask fee.\n * - `totals.total` should represent Amount + Transaction Fee using the totals pipeline.\n */\nfunction combineQuotes({\n adjustedAmountFiat,\n amountFiat,\n fiatQuote,\n relayQuote,\n}: {\n adjustedAmountFiat: string;\n amountFiat: string;\n fiatQuote: RampsQuote;\n relayQuote: TransactionPayQuote<RelayQuote>;\n}): TransactionPayQuote<FiatQuote> {\n const rampsProviderFee = getRampsProviderFee(fiatQuote);\n const totalProviderFee = new BigNumber(relayQuote.fees.provider.usd)\n .plus(rampsProviderFee)\n .toString(10);\n const rampsProviderFeeStr = rampsProviderFee.toString(10);\n const metaMaskFee = getMetaMaskFee({\n adjustedAmountFiat,\n amountFiat,\n }).toString(10);\n\n return {\n ...relayQuote,\n fees: {\n ...relayQuote.fees,\n metaMask: {\n fiat: metaMaskFee,\n usd: metaMaskFee,\n },\n provider: {\n fiat: totalProviderFee,\n usd: totalProviderFee,\n },\n providerFiat: {\n fiat: rampsProviderFeeStr,\n usd: rampsProviderFeeStr,\n },\n },\n original: {\n rampsQuote: fiatQuote,\n relayQuote: relayQuote.original,\n },\n strategy: TransactionPayStrategy.Fiat,\n };\n}\n\n/**\n * Ramps providers handle network gas fees themselves but report them separately\n * as `networkFee` alongside their `providerFee`. We combine both into a single\n * ramps provider fee for the `providerFiat` breakdown.\n *\n * @param fiatQuote - The ramps quote containing provider and network fees.\n * @returns Combined ramps provider fee as a BigNumber.\n */\nfunction getRampsProviderFee(fiatQuote: RampsQuote): BigNumber {\n return new BigNumber(fiatQuote.quote.providerFee ?? 0).plus(\n fiatQuote.quote.networkFee ?? 0,\n );\n}\n\nfunction getRelayTotalFeeUsd(\n relayQuote: TransactionPayQuote<RelayQuote>,\n): BigNumber {\n return new BigNumber(relayQuote.fees.provider.usd)\n .plus(relayQuote.fees.sourceNetwork.estimate.usd)\n .plus(relayQuote.fees.targetNetwork.usd)\n .plus(relayQuote.fees.metaMask.usd);\n}\n\nfunction getNonGasRelayFeeUsd(\n relayQuote: TransactionPayQuote<RelayQuote>,\n): BigNumber {\n return new BigNumber(relayQuote.fees.provider.usd)\n .plus(relayQuote.fees.targetNetwork.usd)\n .plus(relayQuote.fees.metaMask.usd);\n}\n\nfunction getMetaMaskFee({\n adjustedAmountFiat,\n amountFiat,\n}: {\n adjustedAmountFiat: BigNumber.Value;\n amountFiat: BigNumber.Value;\n}): BigNumber {\n return new BigNumber(amountFiat).plus(adjustedAmountFiat).dividedBy(100);\n}\n"]}
1
+ {"version":3,"file":"fiat-quotes.js","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-quotes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAQhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EACL,6BAA6B,E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AI,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["import type { Quote as RampsQuote } from '@metamask/ramps-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n NATIVE_TOKEN_ADDRESS,\n TransactionPayStrategy,\n} from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionFiatPayment,\n TransactionPayRequiredToken,\n TransactionPayQuote,\n} from '../../types.js';\nimport { getDirectMoneyMusdEnabled } from '../../utils/feature-flags.js';\nimport {\n buildCaipAssetType,\n computeRawFromFiatAmount,\n getTokenFiatRate,\n getTokenInfo,\n} from '../../utils/token.js';\nimport { getRelayQuotes } from '../relay/relay-quotes.js';\nimport type { RelayQuote } from '../relay/types.js';\nimport type { TransactionPayFiatAsset } from './constants.js';\nimport { getDirectMusdFiatQuote } from './fiat-direct-musd.js';\nimport type { FiatQuote } from './types.js';\nimport {\n deriveFiatAssetForFiatPayment,\n getNativeTransakRampsFee,\n getRampsQuote,\n isMoneyAccountDepositTransaction,\n} from './utils.js';\n\nconst log = createModuleLogger(projectLogger, 'fiat-strategy');\n\ntype FiatQuotePipelineOptions = {\n amountFiat: string;\n fiatAsset: TransactionPayFiatAsset;\n fiatPaymentMethod: string;\n rampsWalletAddress: Hex;\n requiredTokens: TransactionPayRequiredToken[];\n};\n\n/**\n * Fetches MM Pay fiat strategy quotes using a relay-first estimation flow.\n *\n * When the direct-to-mUSD flag is enabled and the transaction is a Money\n * Account deposit, uses direct mUSD params (asset, wallet, recipient).\n * Otherwise, uses the standard ETH flow.\n *\n * @param request - Strategy quotes request.\n * @returns A single combined fiat strategy quote, or an empty array when inputs/quotes are unavailable.\n */\nexport async function getFiatQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<FiatQuote>[]> {\n const { messenger, transaction } = request;\n\n const state = messenger.call('TransactionPayController:getState');\n const transactionData = state.transactionData[transaction.id];\n const amountFiat = transactionData?.fiatPayment?.amountFiat;\n const requiredTokens = transactionData?.tokens ?? [];\n\n if (\n !amountFiat ||\n !request.fiatPaymentMethod ||\n requiredTokens.length !== 1\n ) {\n return [];\n }\n\n const useDirectMusd =\n getDirectMoneyMusdEnabled(messenger) &&\n isMoneyAccountDepositTransaction(transaction);\n\n if (useDirectMusd) {\n const requiredToken = requiredTokens[0];\n\n const directQuote = await getDirectMusdFiatQuote({\n amountFiat,\n fiatPaymentMethod: request.fiatPaymentMethod,\n messenger,\n moneyAccountAddress: transaction.txParams.from as Hex,\n requiredToken,\n transactionId: transaction.id,\n });\n\n return directQuote ? [directQuote] : [];\n }\n\n return executeFiatQuotePipeline(request, {\n amountFiat,\n fiatAsset: deriveFiatAssetForFiatPayment(transaction, messenger),\n fiatPaymentMethod: request.fiatPaymentMethod,\n rampsWalletAddress: request.from,\n requiredTokens,\n });\n}\n\nasync function executeFiatQuotePipeline(\n request: PayStrategyGetQuotesRequest,\n options: FiatQuotePipelineOptions,\n): Promise<TransactionPayQuote<FiatQuote>[]> {\n const {\n accountSupports7702,\n from: walletAddress,\n messenger,\n transaction,\n } = request;\n const {\n amountFiat,\n fiatAsset,\n fiatPaymentMethod,\n rampsWalletAddress,\n requiredTokens,\n } = options;\n const transactionId = transaction.id;\n\n try {\n const requiredToken = requiredTokens[0];\n\n const relayRequest = buildRelayRequestFromAmountFiat({\n amountFiat,\n fiatAsset,\n messenger,\n requiredToken,\n walletAddress,\n });\n\n if (!relayRequest) {\n throw new Error('Failed to build relay request from fiat amount');\n }\n\n const relayQuotes = await getRelayQuotes({\n accountSupports7702,\n from: walletAddress,\n messenger,\n requests: [relayRequest],\n transaction,\n });\n\n const relayQuote = relayQuotes[0];\n if (!relayQuote) {\n throw new Error('No relay quote available for fiat estimation');\n }\n\n const isSourceNative =\n fiatAsset.address.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase();\n const gasDeductedFromSource =\n isSourceNative || relayQuote.fees.isSourceGasFeeToken === true;\n\n const relayTotalFeeUsd = gasDeductedFromSource\n ? getRelayTotalFeeUsd(relayQuote)\n : getNonGasRelayFeeUsd(relayQuote);\n const adjustedAmountFiat = new BigNumber(amountFiat).plus(relayTotalFeeUsd);\n\n if (\n !adjustedAmountFiat.isFinite() ||\n !adjustedAmountFiat.gt(0) ||\n !relayTotalFeeUsd.isFinite() ||\n !relayTotalFeeUsd.gte(0)\n ) {\n throw new Error('Invalid fiat amount after relay fee adjustment');\n }\n\n const adjustedAmount = adjustedAmountFiat.toNumber();\n\n if (!Number.isFinite(adjustedAmount) || adjustedAmount <= 0) {\n throw new Error('Invalid fiat amount after relay fee adjustment');\n }\n\n log('Fiat quote flow', {\n adjustedAmountFiat: adjustedAmountFiat.toString(10),\n amountFiat,\n rampsWalletAddress,\n relayTotalFeeUsd: relayTotalFeeUsd.toString(10),\n sourceAmountRaw: relayRequest.sourceTokenAmount,\n transactionId,\n });\n\n const fiatQuote = await getRampsQuote({\n adjustedAmount,\n fiatAsset,\n fiatPaymentMethod,\n messenger,\n walletAddress: rampsWalletAddress,\n });\n\n // When Transak Native is the resolved provider, prefer its own quote's fee\n // so the estimate matches what Transak Native will charge. The relay path\n // stays fee-on-top, so request the native quote in the same mode.\n const nativeRampsFee = await getNativeTransakRampsFee({\n adjustedAmount,\n fiatAsset,\n fiatPaymentMethod,\n fiatQuote,\n isFeeExcludedFromFiat: true,\n messenger,\n });\n\n messenger.call('TransactionPayController:updateFiatPayment', {\n callback: (fiatPayment: TransactionFiatPayment) => {\n fiatPayment.rampsQuote = fiatQuote;\n fiatPayment.caipAssetId = buildCaipAssetType(\n fiatAsset.chainId,\n fiatAsset.address,\n );\n },\n transactionId,\n });\n\n return [\n combineQuotes({\n adjustedAmountFiat: adjustedAmountFiat.toString(10),\n amountFiat,\n fiatQuote,\n nativeRampsFee,\n relayQuote,\n }),\n ];\n } catch (error) {\n log('Failed to fetch fiat quotes', { error, transactionId });\n\n messenger.call('TransactionPayController:updateFiatPayment', {\n callback: (fiatPayment) => {\n fiatPayment.rampsQuote = undefined;\n },\n transactionId,\n });\n }\n\n return [];\n}\n\nfunction buildRelayRequestFromAmountFiat({\n amountFiat,\n fiatAsset,\n messenger,\n requiredToken,\n walletAddress,\n}: {\n amountFiat: string;\n fiatAsset: {\n address: Hex;\n chainId: Hex;\n };\n messenger: PayStrategyGetQuotesRequest['messenger'];\n requiredToken: TransactionPayRequiredToken;\n walletAddress: Hex;\n}): QuoteRequest | undefined {\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n fiatAsset.address,\n fiatAsset.chainId,\n );\n\n if (!sourceFiatRate) {\n return undefined;\n }\n\n const tokenInfo = getTokenInfo(\n messenger,\n fiatAsset.address,\n fiatAsset.chainId,\n );\n\n if (!tokenInfo) {\n return undefined;\n }\n\n const sourceAmountRaw = computeRawFromFiatAmount(\n amountFiat,\n tokenInfo.decimals,\n sourceFiatRate.usdRate,\n );\n\n if (!sourceAmountRaw) {\n return undefined;\n }\n\n return {\n from: walletAddress,\n // Force EXACT_INPUT mode: source amount is pre-calculated from the fiat\n // amount, so the relay should treat it as a fixed input rather than\n // computing it from the target.\n isPostQuote: true,\n sourceBalanceRaw: sourceAmountRaw,\n sourceChainId: fiatAsset.chainId,\n sourceTokenAddress: fiatAsset.address,\n sourceTokenAmount: sourceAmountRaw,\n targetAmountMinimum: requiredToken.amountRaw,\n targetChainId: requiredToken.chainId,\n targetTokenAddress: requiredToken.address,\n };\n}\n\n/**\n * Combines fiat and relay legs into a single MM Pay fiat strategy quote.\n *\n * @param params - Combined quote inputs.\n * @param params.adjustedAmountFiat - Fiat amount sent to ramps after adding relay fee estimate.\n * @param params.amountFiat - User-entered fiat amount.\n * @param params.fiatQuote - Selected ramps quote.\n * @param params.nativeRampsFee - Native Transak fee to use in place of the aggregator ramps fee, or null.\n * @param params.relayQuote - Estimated relay quote.\n * @returns A single fiat strategy quote with split fee buckets.\n * @remarks\n * Fee mapping contract for MM Pay Fiat strategy:\n * - `fees.provider`: Total provider fee (relay provider/swap fee + ramps provider/network fee).\n * Consumed by UI transaction fee row and tooltip provider fee.\n * - `fees.providerFiat`: Fiat on-ramp provider fees only (`providerFee + networkFee` from ramps quote).\n * Optional breakdown; client can derive relay portion via `provider - providerFiat`.\n * - `fees.sourceNetwork` / `fees.targetNetwork`: Relay settlement network fees.\n * Consumed by UI transaction fee row and tooltip network fee.\n * - `fees.metaMask`: MM Pay fee (currently 100 bps over `amountFiat + adjustedAmountFiat`).\n * Consumed by UI transaction fee row and tooltip MetaMask fee.\n * - `totals.total` should represent Amount + Transaction Fee using the totals pipeline.\n */\nfunction combineQuotes({\n adjustedAmountFiat,\n amountFiat,\n fiatQuote,\n nativeRampsFee,\n relayQuote,\n}: {\n adjustedAmountFiat: string;\n amountFiat: string;\n fiatQuote: RampsQuote;\n nativeRampsFee: BigNumber | null;\n relayQuote: TransactionPayQuote<RelayQuote>;\n}): TransactionPayQuote<FiatQuote> {\n const rampsProviderFee = nativeRampsFee ?? getRampsProviderFee(fiatQuote);\n const totalProviderFee = new BigNumber(relayQuote.fees.provider.usd)\n .plus(rampsProviderFee)\n .toString(10);\n const rampsProviderFeeStr = rampsProviderFee.toString(10);\n const metaMaskFee = getMetaMaskFee({\n adjustedAmountFiat,\n amountFiat,\n }).toString(10);\n\n return {\n ...relayQuote,\n fees: {\n ...relayQuote.fees,\n metaMask: {\n fiat: metaMaskFee,\n usd: metaMaskFee,\n },\n provider: {\n fiat: totalProviderFee,\n usd: totalProviderFee,\n },\n providerFiat: {\n fiat: rampsProviderFeeStr,\n usd: rampsProviderFeeStr,\n },\n },\n original: {\n rampsQuote: fiatQuote,\n relayQuote: relayQuote.original,\n },\n strategy: TransactionPayStrategy.Fiat,\n };\n}\n\n/**\n * Ramps providers handle network gas fees themselves but report them separately\n * as `networkFee` alongside their `providerFee`. We combine both into a single\n * ramps provider fee for the `providerFiat` breakdown.\n *\n * @param fiatQuote - The ramps quote containing provider and network fees.\n * @returns Combined ramps provider fee as a BigNumber.\n */\nfunction getRampsProviderFee(fiatQuote: RampsQuote): BigNumber {\n return new BigNumber(fiatQuote.quote.providerFee ?? 0).plus(\n fiatQuote.quote.networkFee ?? 0,\n );\n}\n\nfunction getRelayTotalFeeUsd(\n relayQuote: TransactionPayQuote<RelayQuote>,\n): BigNumber {\n return new BigNumber(relayQuote.fees.provider.usd)\n .plus(relayQuote.fees.sourceNetwork.estimate.usd)\n .plus(relayQuote.fees.targetNetwork.usd)\n .plus(relayQuote.fees.metaMask.usd);\n}\n\nfunction getNonGasRelayFeeUsd(\n relayQuote: TransactionPayQuote<RelayQuote>,\n): BigNumber {\n return new BigNumber(relayQuote.fees.provider.usd)\n .plus(relayQuote.fees.targetNetwork.usd)\n .plus(relayQuote.fees.metaMask.usd);\n}\n\nfunction getMetaMaskFee({\n adjustedAmountFiat,\n amountFiat,\n}: {\n adjustedAmountFiat: BigNumber.Value;\n amountFiat: BigNumber.Value;\n}): BigNumber {\n return new BigNumber(amountFiat).plus(adjustedAmountFiat).dividedBy(100);\n}\n"]}
@@ -2,6 +2,7 @@ import type { Quote as RampsQuote, RampsOrder, RampsOrderCryptoCurrency } from '
2
2
  import type { TransactionMeta } from '@metamask/transaction-controller';
3
3
  import { TransactionType } from '@metamask/transaction-controller';
4
4
  import type { Hex } from '@metamask/utils';
5
+ import { BigNumber } from 'bignumber.js';
5
6
  import type { TransactionPayControllerMessenger } from '../../types.js';
6
7
  import type { RelayQuote } from '../relay/types.js';
7
8
  import type { TransactionPayFiatAsset } from './constants.js';
@@ -32,13 +33,7 @@ export declare function resolveTransactionType(transaction: TransactionMeta, ena
32
33
  */
33
34
  export declare function isMoneyAccountDepositTransaction(transaction: TransactionMeta): boolean;
34
35
  /**
35
- * Fetches the best matching Ramps quote for a fiat asset and payment method,
36
- * with provider fees reconciled to what the resolved provider actually charges.
37
- *
38
- * The `RampsController:getQuoteWithFees` action owns the provider check and the
39
- * native buy-quote lookup, so a Transak Native quote already carries the native
40
- * fee in its `providerFee`/`networkFee`/`totalFees` fields. MM Pay deposits are
41
- * fee-on-top, so the quote is requested with `isFeeExcludedFromFiat: true`.
36
+ * Fetches the first matching Ramps quote for a fiat asset and payment method.
42
37
  *
43
38
  * @param options - Quote options.
44
39
  * @param options.adjustedAmount - Fiat amount sent to Ramps.
@@ -47,7 +42,7 @@ export declare function isMoneyAccountDepositTransaction(transaction: Transactio
47
42
  * @param options.fiatPaymentMethod - Selected fiat payment method.
48
43
  * @param options.messenger - Controller messenger.
49
44
  * @param options.walletAddress - Wallet address that receives the on-ramped asset.
50
- * @returns The best matching Ramps quote with reconciled fees.
45
+ * @returns The first matching Ramps quote.
51
46
  */
52
47
  export declare function getRampsQuote({ adjustedAmount, errorMessage, fiatAsset, fiatPaymentMethod, messenger, walletAddress, }: {
53
48
  adjustedAmount: number;
@@ -151,4 +146,34 @@ export declare function validateRelayRateDrift({ originalQuote, discoveryQuote,
151
146
  * @returns The provider code, or `null` if the format is invalid.
152
147
  */
153
148
  export declare function extractProviderCode(provider: string | undefined): string | null;
149
+ /**
150
+ * When the resolved ramps provider is Transak Native, fetches the native
151
+ * Transak buy quote and returns its total fee so the estimate matches what
152
+ * Transak Native actually charges.
153
+ *
154
+ * The native lookup (`/api/v2/lookup/quotes`) is an unauthenticated, API-key
155
+ * only call, so it is safe to run at estimate time before the user signs in to
156
+ * Transak. Returns `null` when the provider is not Transak Native, or when the
157
+ * native lookup fails or returns an unusable fee, so the caller falls back to
158
+ * the aggregator quote's fee.
159
+ *
160
+ * @param options - Native fee options.
161
+ * @param options.adjustedAmount - Fiat amount (USD) sent to ramps.
162
+ * @param options.fiatAsset - Fiat asset being bought.
163
+ * @param options.fiatPaymentMethod - Selected fiat payment method.
164
+ * @param options.fiatQuote - The resolved aggregator quote (used to detect native).
165
+ * @param options.isFeeExcludedFromFiat - Whether Transak adds its fee on top of
166
+ * the fiat amount (`true`) or carves it out of the amount (`false`). Must mirror
167
+ * the eventual checkout mode so the estimate equals the charge.
168
+ * @param options.messenger - Controller messenger.
169
+ * @returns The native total fee as a BigNumber, or `null` to use the aggregator fee.
170
+ */
171
+ export declare function getNativeTransakRampsFee({ adjustedAmount, fiatAsset, fiatPaymentMethod, fiatQuote, isFeeExcludedFromFiat, messenger, }: {
172
+ adjustedAmount: number;
173
+ fiatAsset: TransactionPayFiatAsset;
174
+ fiatPaymentMethod: string;
175
+ fiatQuote: RampsQuote;
176
+ isFeeExcludedFromFiat: boolean;
177
+ messenger: TransactionPayControllerMessenger;
178
+ }): Promise<BigNumber | null>;
154
179
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/strategy/fiat/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,IAAI,UAAU,EACnB,UAAU,EACV,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAK3C,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAOxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAK9D,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,eAAe,EAC5B,SAAS,EAAE,iCAAiC,GAC3C,uBAAuB,CAKzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,eAAe,EAC5B,YAAY,EAAE,eAAe,EAAE,GAC9B,eAAe,GAAG,SAAS,CAU7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB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AAc,CAAC,CAAC;IACzC,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,CAmBT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,aAAa,GACd,EAAE;IACD,aAAa,EAAE,UAAU,CAAC;IAC1B,cAAc,EAAE,UAAU,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CA2CP;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,MAAM,GAAG,IAAI,CAYf;AAWD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,SAAS,GACV,EAAE;IACD,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,uBAAuB,CAAC;IACnC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,UAAU,CAAC;IACtB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,SAAS,EAAE,iCAAiC,CAAC;CAC9C,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAsC5B"}
@@ -47,13 +47,7 @@ export function isMoneyAccountDepositTransaction(transaction) {
47
47
  TransactionType.moneyAccountDeposit);
48
48
  }
49
49
  /**
50
- * Fetches the best matching Ramps quote for a fiat asset and payment method,
51
- * with provider fees reconciled to what the resolved provider actually charges.
52
- *
53
- * The `RampsController:getQuoteWithFees` action owns the provider check and the
54
- * native buy-quote lookup, so a Transak Native quote already carries the native
55
- * fee in its `providerFee`/`networkFee`/`totalFees` fields. MM Pay deposits are
56
- * fee-on-top, so the quote is requested with `isFeeExcludedFromFiat: true`.
50
+ * Fetches the first matching Ramps quote for a fiat asset and payment method.
57
51
  *
58
52
  * @param options - Quote options.
59
53
  * @param options.adjustedAmount - Fiat amount sent to Ramps.
@@ -62,20 +56,22 @@ export function isMoneyAccountDepositTransaction(transaction) {
62
56
  * @param options.fiatPaymentMethod - Selected fiat payment method.
63
57
  * @param options.messenger - Controller messenger.
64
58
  * @param options.walletAddress - Wallet address that receives the on-ramped asset.
65
- * @returns The best matching Ramps quote with reconciled fees.
59
+ * @returns The first matching Ramps quote.
66
60
  */
67
61
  export async function getRampsQuote({ adjustedAmount, errorMessage = 'No matching ramps quote found for selected provider', fiatAsset, fiatPaymentMethod, messenger, walletAddress, }) {
68
- const quote = await messenger.call('RampsController:getQuoteWithFees', {
62
+ const quotes = await messenger.call('RampsController:getQuotes', {
69
63
  amount: adjustedAmount,
70
64
  assetId: buildCaipAssetType(fiatAsset.chainId, fiatAsset.address),
71
65
  autoSelectProvider: true,
72
66
  fiat: DEFAULT_FIAT_CURRENCY,
73
- isFeeExcludedFromFiat: true,
74
67
  paymentMethods: [fiatPaymentMethod],
75
68
  restrictToKnownOrNativeProviders: true,
76
69
  walletAddress,
77
70
  });
78
- log('Fetched ramps quote', { hasQuote: Boolean(quote) });
71
+ log('Fetched ramps quotes', {
72
+ quotesCount: quotes.success?.length ?? 0,
73
+ });
74
+ const quote = quotes.success?.[0];
79
75
  if (!quote) {
80
76
  throw new Error(errorMessage);
81
77
  }
@@ -238,4 +234,57 @@ export function extractProviderCode(provider) {
238
234
  }
239
235
  return parts.length === 1 ? parts[0] : null;
240
236
  }
237
+ /**
238
+ * Provider codes that identify Transak's native (non-aggregator) integration.
239
+ * Matches the codes emitted by `TransakService` for production and staging.
240
+ */
241
+ const NATIVE_TRANSAK_PROVIDER_CODES = [
242
+ 'transak-native',
243
+ 'transak-native-staging',
244
+ ];
245
+ /**
246
+ * When the resolved ramps provider is Transak Native, fetches the native
247
+ * Transak buy quote and returns its total fee so the estimate matches what
248
+ * Transak Native actually charges.
249
+ *
250
+ * The native lookup (`/api/v2/lookup/quotes`) is an unauthenticated, API-key
251
+ * only call, so it is safe to run at estimate time before the user signs in to
252
+ * Transak. Returns `null` when the provider is not Transak Native, or when the
253
+ * native lookup fails or returns an unusable fee, so the caller falls back to
254
+ * the aggregator quote's fee.
255
+ *
256
+ * @param options - Native fee options.
257
+ * @param options.adjustedAmount - Fiat amount (USD) sent to ramps.
258
+ * @param options.fiatAsset - Fiat asset being bought.
259
+ * @param options.fiatPaymentMethod - Selected fiat payment method.
260
+ * @param options.fiatQuote - The resolved aggregator quote (used to detect native).
261
+ * @param options.isFeeExcludedFromFiat - Whether Transak adds its fee on top of
262
+ * the fiat amount (`true`) or carves it out of the amount (`false`). Must mirror
263
+ * the eventual checkout mode so the estimate equals the charge.
264
+ * @param options.messenger - Controller messenger.
265
+ * @returns The native total fee as a BigNumber, or `null` to use the aggregator fee.
266
+ */
267
+ export async function getNativeTransakRampsFee({ adjustedAmount, fiatAsset, fiatPaymentMethod, fiatQuote, isFeeExcludedFromFiat, messenger, }) {
268
+ const providerCode = extractProviderCode(fiatQuote.provider);
269
+ if (!providerCode || !NATIVE_TRANSAK_PROVIDER_CODES.includes(providerCode)) {
270
+ return null;
271
+ }
272
+ try {
273
+ const assetId = buildCaipAssetType(fiatAsset.chainId, fiatAsset.address);
274
+ const network = assetId.split('/')[0];
275
+ const nativeQuote = await messenger.call('TransakService:getBuyQuote', DEFAULT_FIAT_CURRENCY, assetId, network, fiatPaymentMethod, String(adjustedAmount), isFeeExcludedFromFiat);
276
+ const fee = new BigNumber(nativeQuote.totalFee ?? NaN);
277
+ if (!fee.isFinite() || fee.isLessThan(0)) {
278
+ log('Native Transak quote returned an unusable fee; using aggregator fee', {
279
+ totalFee: nativeQuote.totalFee,
280
+ });
281
+ return null;
282
+ }
283
+ return fee;
284
+ }
285
+ catch (error) {
286
+ log('Native Transak fee fetch failed; using aggregator fee', { error });
287
+ return null;
288
+ }
289
+ }
241
290
  //# sourceMappingURL=utils.js.map