@metamask/transaction-pay-controller 18.0.0 → 18.1.0
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.
- package/CHANGELOG.md +16 -1
- package/dist/TransactionPayController-method-action-types.cjs +1 -1
- package/dist/TransactionPayController-method-action-types.cjs.map +1 -1
- package/dist/TransactionPayController-method-action-types.d.cts +1 -1
- package/dist/TransactionPayController-method-action-types.d.mts +1 -1
- package/dist/TransactionPayController-method-action-types.mjs +1 -1
- package/dist/TransactionPayController-method-action-types.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/strategy/across/across-actions.cjs +185 -0
- package/dist/strategy/across/across-actions.cjs.map +1 -0
- package/dist/strategy/across/across-actions.d.cts +21 -0
- package/dist/strategy/across/across-actions.d.cts.map +1 -0
- package/dist/strategy/across/across-actions.d.mts +21 -0
- package/dist/strategy/across/across-actions.d.mts.map +1 -0
- package/dist/strategy/across/across-actions.mjs +178 -0
- package/dist/strategy/across/across-actions.mjs.map +1 -0
- package/dist/strategy/across/across-quotes.cjs +2 -72
- package/dist/strategy/across/across-quotes.cjs.map +1 -1
- package/dist/strategy/across/across-quotes.d.cts.map +1 -1
- package/dist/strategy/across/across-quotes.d.mts.map +1 -1
- package/dist/strategy/across/across-quotes.mjs +1 -71
- package/dist/strategy/across/across-quotes.mjs.map +1 -1
- package/dist/strategy/fiat/FiatStrategy.cjs +15 -0
- package/dist/strategy/fiat/FiatStrategy.cjs.map +1 -0
- package/dist/strategy/fiat/FiatStrategy.d.cts +7 -0
- package/dist/strategy/fiat/FiatStrategy.d.cts.map +1 -0
- package/dist/strategy/fiat/FiatStrategy.d.mts +7 -0
- package/dist/strategy/fiat/FiatStrategy.d.mts.map +1 -0
- package/dist/strategy/fiat/FiatStrategy.mjs +11 -0
- package/dist/strategy/fiat/FiatStrategy.mjs.map +1 -0
- package/dist/strategy/fiat/constants.cjs +24 -0
- package/dist/strategy/fiat/constants.cjs.map +1 -0
- package/dist/strategy/fiat/constants.d.cts +10 -0
- package/dist/strategy/fiat/constants.d.cts.map +1 -0
- package/dist/strategy/fiat/constants.d.mts +10 -0
- package/dist/strategy/fiat/constants.d.mts.map +1 -0
- package/dist/strategy/fiat/constants.mjs +21 -0
- package/dist/strategy/fiat/constants.mjs.map +1 -0
- package/dist/strategy/fiat/fiat-quotes.cjs +214 -0
- package/dist/strategy/fiat/fiat-quotes.cjs.map +1 -0
- package/dist/strategy/fiat/fiat-quotes.d.cts +17 -0
- package/dist/strategy/fiat/fiat-quotes.d.cts.map +1 -0
- package/dist/strategy/fiat/fiat-quotes.d.mts +17 -0
- package/dist/strategy/fiat/fiat-quotes.d.mts.map +1 -0
- package/dist/strategy/fiat/fiat-quotes.mjs +210 -0
- package/dist/strategy/fiat/fiat-quotes.mjs.map +1 -0
- package/dist/strategy/fiat/fiat-submit.cjs +14 -0
- package/dist/strategy/fiat/fiat-submit.cjs.map +1 -0
- package/dist/strategy/fiat/fiat-submit.d.cts +10 -0
- package/dist/strategy/fiat/fiat-submit.d.cts.map +1 -0
- package/dist/strategy/fiat/fiat-submit.d.mts +10 -0
- package/dist/strategy/fiat/fiat-submit.d.mts.map +1 -0
- package/dist/strategy/fiat/fiat-submit.mjs +10 -0
- package/dist/strategy/fiat/fiat-submit.mjs.map +1 -0
- package/dist/strategy/fiat/types.cjs +3 -0
- package/dist/strategy/fiat/types.cjs.map +1 -0
- package/dist/strategy/fiat/types.d.cts +8 -0
- package/dist/strategy/fiat/types.d.cts.map +1 -0
- package/dist/strategy/fiat/types.d.mts +8 -0
- package/dist/strategy/fiat/types.d.mts.map +1 -0
- package/dist/strategy/fiat/types.mjs +2 -0
- package/dist/strategy/fiat/types.mjs.map +1 -0
- package/dist/strategy/fiat/utils.cjs +23 -0
- package/dist/strategy/fiat/utils.cjs.map +1 -0
- package/dist/strategy/fiat/utils.d.cts +6 -0
- package/dist/strategy/fiat/utils.d.cts.map +1 -0
- package/dist/strategy/fiat/utils.d.mts +6 -0
- package/dist/strategy/fiat/utils.d.mts.map +1 -0
- package/dist/strategy/fiat/utils.mjs +18 -0
- package/dist/strategy/fiat/utils.mjs.map +1 -0
- package/dist/tests/messenger-mock.d.cts +1 -1
- package/dist/tests/messenger-mock.d.mts +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/quotes.cjs +4 -2
- package/dist/utils/quotes.cjs.map +1 -1
- package/dist/utils/quotes.d.cts.map +1 -1
- package/dist/utils/quotes.d.mts.map +1 -1
- package/dist/utils/quotes.mjs +4 -2
- package/dist/utils/quotes.mjs.map +1 -1
- package/dist/utils/strategy.cjs +3 -0
- package/dist/utils/strategy.cjs.map +1 -1
- package/dist/utils/strategy.d.cts.map +1 -1
- package/dist/utils/strategy.d.mts.map +1 -1
- package/dist/utils/strategy.mjs +3 -0
- package/dist/utils/strategy.mjs.map +1 -1
- package/dist/utils/token.cjs +26 -1
- package/dist/utils/token.cjs.map +1 -1
- package/dist/utils/token.d.cts +10 -0
- package/dist/utils/token.d.cts.map +1 -1
- package/dist/utils/token.d.mts +10 -0
- package/dist/utils/token.d.mts.map +1 -1
- package/dist/utils/token.mjs +24 -0
- package/dist/utils/token.mjs.map +1 -1
- package/dist/utils/totals.cjs +2 -0
- package/dist/utils/totals.cjs.map +1 -1
- package/dist/utils/totals.d.cts.map +1 -1
- package/dist/utils/totals.d.mts.map +1 -1
- package/dist/utils/totals.mjs +2 -0
- package/dist/utils/totals.mjs.map +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { deriveFiatAssetForFiatPayment, pickBestFiatQuote } from "./utils.mjs";
|
|
4
|
+
import { TransactionPayStrategy } from "../../constants.mjs";
|
|
5
|
+
import { projectLogger } from "../../logger.mjs";
|
|
6
|
+
import { computeRawFromFiatAmount, getTokenFiatRate } from "../../utils/token.mjs";
|
|
7
|
+
import { getRelayQuotes } from "../relay/relay-quotes.mjs";
|
|
8
|
+
const log = createModuleLogger(projectLogger, 'fiat-strategy');
|
|
9
|
+
/**
|
|
10
|
+
* Fetches MM Pay fiat strategy quotes using a relay-first estimation flow.
|
|
11
|
+
*
|
|
12
|
+
* @param request - Strategy quotes request.
|
|
13
|
+
* @returns A single combined fiat strategy quote, or an empty array when inputs/quotes are unavailable.
|
|
14
|
+
* @remarks
|
|
15
|
+
* Flow summary:
|
|
16
|
+
* 1. Read `amountFiat` and selected payment method from transaction pay state.
|
|
17
|
+
* 2. Build a synthetic relay request from `amountFiat` using source token USD rate.
|
|
18
|
+
* 3. Fetch relay quote and compute total relay fee (`provider + source network + target network + MetaMask`).
|
|
19
|
+
* 4. Call ramps quotes with `adjustedAmountFiat = amountFiat + relayTotalFeeUsd`.
|
|
20
|
+
* 5. Pick the configured ramps provider quote and combine it with relay quote into one fiat strategy quote.
|
|
21
|
+
*/
|
|
22
|
+
export async function getFiatQuotes(request) {
|
|
23
|
+
const { fiatPaymentMethod, messenger, transaction } = request;
|
|
24
|
+
const transactionId = transaction.id;
|
|
25
|
+
const state = messenger.call('TransactionPayController:getState');
|
|
26
|
+
const transactionData = state.transactionData[transactionId];
|
|
27
|
+
const amountFiat = transactionData?.fiatPayment?.amountFiat;
|
|
28
|
+
const walletAddress = transaction.txParams.from;
|
|
29
|
+
const requiredTokens = getRequiredTokens(transactionData?.tokens);
|
|
30
|
+
const fiatAsset = deriveFiatAssetForFiatPayment(transaction);
|
|
31
|
+
if (!amountFiat ||
|
|
32
|
+
!fiatPaymentMethod ||
|
|
33
|
+
!requiredTokens.length ||
|
|
34
|
+
!fiatAsset) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
if (requiredTokens.length > 1) {
|
|
39
|
+
throw new Error('Multiple required tokens not supported for fiat strategy');
|
|
40
|
+
}
|
|
41
|
+
const requiredToken = requiredTokens[0];
|
|
42
|
+
const relayRequest = buildRelayRequestFromAmountFiat({
|
|
43
|
+
amountFiat,
|
|
44
|
+
fiatAsset,
|
|
45
|
+
messenger,
|
|
46
|
+
requiredToken,
|
|
47
|
+
walletAddress,
|
|
48
|
+
});
|
|
49
|
+
if (!relayRequest) {
|
|
50
|
+
throw new Error('Failed to build relay request from fiat amount');
|
|
51
|
+
}
|
|
52
|
+
const relayQuotes = await getRelayQuotes({
|
|
53
|
+
messenger,
|
|
54
|
+
requests: [relayRequest],
|
|
55
|
+
transaction,
|
|
56
|
+
});
|
|
57
|
+
const relayQuote = relayQuotes[0];
|
|
58
|
+
if (!relayQuote) {
|
|
59
|
+
throw new Error('No relay quote available for fiat estimation');
|
|
60
|
+
}
|
|
61
|
+
const relayTotalFeeUsd = getRelayTotalFeeUsd(relayQuote);
|
|
62
|
+
const adjustedAmountFiat = new BigNumber(amountFiat).plus(relayTotalFeeUsd);
|
|
63
|
+
if (!adjustedAmountFiat.isFinite() ||
|
|
64
|
+
!adjustedAmountFiat.gt(0) ||
|
|
65
|
+
!relayTotalFeeUsd.isFinite() ||
|
|
66
|
+
!relayTotalFeeUsd.gte(0)) {
|
|
67
|
+
throw new Error('Invalid fiat amount after relay fee adjustment');
|
|
68
|
+
}
|
|
69
|
+
const adjustedAmount = adjustedAmountFiat.toNumber();
|
|
70
|
+
if (!Number.isFinite(adjustedAmount) || adjustedAmount <= 0) {
|
|
71
|
+
throw new Error('Invalid fiat amount after relay fee adjustment');
|
|
72
|
+
}
|
|
73
|
+
log('Fiat quote flow', {
|
|
74
|
+
adjustedAmountFiat: adjustedAmountFiat.toString(10),
|
|
75
|
+
amountFiat,
|
|
76
|
+
paymentMethods: [fiatPaymentMethod],
|
|
77
|
+
relayTotalFeeUsd: relayTotalFeeUsd.toString(10),
|
|
78
|
+
sourceAmountRaw: relayRequest.sourceTokenAmount,
|
|
79
|
+
transactionId,
|
|
80
|
+
});
|
|
81
|
+
const quotes = await messenger.call('RampsController:getQuotes', {
|
|
82
|
+
amount: adjustedAmount,
|
|
83
|
+
paymentMethods: [fiatPaymentMethod],
|
|
84
|
+
walletAddress,
|
|
85
|
+
});
|
|
86
|
+
log('Fetched ramps quotes', {
|
|
87
|
+
rampsQuotesCount: quotes.success?.length ?? 0,
|
|
88
|
+
transactionId,
|
|
89
|
+
});
|
|
90
|
+
const fiatQuote = pickBestFiatQuote(quotes);
|
|
91
|
+
if (!fiatQuote) {
|
|
92
|
+
throw new Error('No matching ramps quote found for selected provider');
|
|
93
|
+
}
|
|
94
|
+
return [
|
|
95
|
+
combineQuotes({
|
|
96
|
+
adjustedAmountFiat: adjustedAmountFiat.toString(10),
|
|
97
|
+
amountFiat,
|
|
98
|
+
fiatQuote,
|
|
99
|
+
relayQuote,
|
|
100
|
+
}),
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
log('Failed to fetch fiat quotes', { error, transactionId });
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
function getRequiredTokens(tokens) {
|
|
109
|
+
return tokens?.filter((token) => !token.skipIfBalance) ?? [];
|
|
110
|
+
}
|
|
111
|
+
function buildRelayRequestFromAmountFiat({ amountFiat, fiatAsset, messenger, requiredToken, walletAddress, }) {
|
|
112
|
+
const sourceFiatRate = getTokenFiatRate(messenger, fiatAsset.address, fiatAsset.chainId);
|
|
113
|
+
if (!sourceFiatRate) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const sourceAmountRaw = computeRawFromFiatAmount(amountFiat, fiatAsset.decimals, sourceFiatRate.usdRate);
|
|
117
|
+
if (!sourceAmountRaw) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
from: walletAddress,
|
|
122
|
+
// Force EXACT_INPUT mode: source amount is pre-calculated from the fiat
|
|
123
|
+
// amount, so the relay should treat it as a fixed input rather than
|
|
124
|
+
// computing it from the target.
|
|
125
|
+
isPostQuote: true,
|
|
126
|
+
sourceBalanceRaw: sourceAmountRaw,
|
|
127
|
+
sourceChainId: fiatAsset.chainId,
|
|
128
|
+
sourceTokenAddress: fiatAsset.address,
|
|
129
|
+
sourceTokenAmount: sourceAmountRaw,
|
|
130
|
+
targetAmountMinimum: requiredToken.amountRaw,
|
|
131
|
+
targetChainId: requiredToken.chainId,
|
|
132
|
+
targetTokenAddress: requiredToken.address,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Combines fiat and relay legs into a single MM Pay fiat strategy quote.
|
|
137
|
+
*
|
|
138
|
+
* @param params - Combined quote inputs.
|
|
139
|
+
* @param params.adjustedAmountFiat - Fiat amount sent to ramps after adding relay fee estimate.
|
|
140
|
+
* @param params.amountFiat - User-entered fiat amount.
|
|
141
|
+
* @param params.fiatQuote - Selected ramps quote.
|
|
142
|
+
* @param params.relayQuote - Estimated relay quote.
|
|
143
|
+
* @returns A single fiat strategy quote with split fee buckets.
|
|
144
|
+
* @remarks
|
|
145
|
+
* Fee mapping contract for MM Pay Fiat strategy:
|
|
146
|
+
* - `fees.provider`: Total provider fee (relay provider/swap fee + ramps provider/network fee).
|
|
147
|
+
* Consumed by UI transaction fee row and tooltip provider fee.
|
|
148
|
+
* - `fees.providerFiat`: Fiat on-ramp provider fees only (`providerFee + networkFee` from ramps quote).
|
|
149
|
+
* Optional breakdown; client can derive relay portion via `provider - providerFiat`.
|
|
150
|
+
* - `fees.sourceNetwork` / `fees.targetNetwork`: Relay settlement network fees.
|
|
151
|
+
* Consumed by UI transaction fee row and tooltip network fee.
|
|
152
|
+
* - `fees.metaMask`: MM Pay fee (currently 100 bps over `amountFiat + adjustedAmountFiat`).
|
|
153
|
+
* Consumed by UI transaction fee row and tooltip MetaMask fee.
|
|
154
|
+
* - `totals.total` should represent Amount + Transaction Fee using the totals pipeline.
|
|
155
|
+
*/
|
|
156
|
+
function combineQuotes({ adjustedAmountFiat, amountFiat, fiatQuote, relayQuote, }) {
|
|
157
|
+
const rampsProviderFee = getRampsProviderFee(fiatQuote);
|
|
158
|
+
const totalProviderFee = new BigNumber(relayQuote.fees.provider.usd)
|
|
159
|
+
.plus(rampsProviderFee)
|
|
160
|
+
.toString(10);
|
|
161
|
+
const rampsProviderFeeStr = rampsProviderFee.toString(10);
|
|
162
|
+
const metaMaskFee = getMetaMaskFee({
|
|
163
|
+
adjustedAmountFiat,
|
|
164
|
+
amountFiat,
|
|
165
|
+
}).toString(10);
|
|
166
|
+
return {
|
|
167
|
+
...relayQuote,
|
|
168
|
+
fees: {
|
|
169
|
+
...relayQuote.fees,
|
|
170
|
+
metaMask: {
|
|
171
|
+
fiat: metaMaskFee,
|
|
172
|
+
usd: metaMaskFee,
|
|
173
|
+
},
|
|
174
|
+
provider: {
|
|
175
|
+
fiat: totalProviderFee,
|
|
176
|
+
usd: totalProviderFee,
|
|
177
|
+
},
|
|
178
|
+
providerFiat: {
|
|
179
|
+
fiat: rampsProviderFeeStr,
|
|
180
|
+
usd: rampsProviderFeeStr,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
original: {
|
|
184
|
+
rampsQuote: fiatQuote,
|
|
185
|
+
relayQuote: relayQuote.original,
|
|
186
|
+
},
|
|
187
|
+
strategy: TransactionPayStrategy.Fiat,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Ramps providers handle network gas fees themselves but report them separately
|
|
192
|
+
* as `networkFee` alongside their `providerFee`. We combine both into a single
|
|
193
|
+
* ramps provider fee for the `providerFiat` breakdown.
|
|
194
|
+
*
|
|
195
|
+
* @param fiatQuote - The ramps quote containing provider and network fees.
|
|
196
|
+
* @returns Combined ramps provider fee as a BigNumber.
|
|
197
|
+
*/
|
|
198
|
+
function getRampsProviderFee(fiatQuote) {
|
|
199
|
+
return new BigNumber(fiatQuote.quote.providerFee ?? 0).plus(fiatQuote.quote.networkFee ?? 0);
|
|
200
|
+
}
|
|
201
|
+
function getRelayTotalFeeUsd(relayQuote) {
|
|
202
|
+
return new BigNumber(relayQuote.fees.provider.usd)
|
|
203
|
+
.plus(relayQuote.fees.sourceNetwork.estimate.usd)
|
|
204
|
+
.plus(relayQuote.fees.targetNetwork.usd)
|
|
205
|
+
.plus(relayQuote.fees.metaMask.usd);
|
|
206
|
+
}
|
|
207
|
+
function getMetaMaskFee({ adjustedAmountFiat, amountFiat, }) {
|
|
208
|
+
return new BigNumber(amountFiat).plus(adjustedAmountFiat).dividedBy(100);
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=fiat-quotes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fiat-quotes.mjs","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-quotes.ts"],"names":[],"mappings":"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","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 type { FiatQuote } from './types';\nimport { deriveFiatAssetForFiatPayment, pickBestFiatQuote } from './utils';\nimport { TransactionPayStrategy } from '../../constants';\nimport { projectLogger } from '../../logger';\nimport type {\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayRequiredToken,\n TransactionPayQuote,\n} from '../../types';\nimport { computeRawFromFiatAmount, getTokenFiatRate } from '../../utils/token';\nimport { getRelayQuotes } from '../relay/relay-quotes';\nimport type { RelayQuote } from '../relay/types';\n\nconst log = createModuleLogger(projectLogger, 'fiat-strategy');\n\n/**\n * Fetches MM Pay fiat strategy quotes using a relay-first estimation 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 * @remarks\n * Flow summary:\n * 1. Read `amountFiat` and selected payment method from transaction pay state.\n * 2. Build a synthetic relay request from `amountFiat` using source token USD rate.\n * 3. Fetch relay quote and compute total relay fee (`provider + source network + target network + MetaMask`).\n * 4. Call ramps quotes with `adjustedAmountFiat = amountFiat + relayTotalFeeUsd`.\n * 5. Pick the configured ramps provider quote and combine it with relay quote into one fiat strategy quote.\n */\nexport async function getFiatQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<FiatQuote>[]> {\n const { fiatPaymentMethod, messenger, transaction } = request;\n const transactionId = transaction.id;\n\n const state = messenger.call('TransactionPayController:getState');\n const transactionData = state.transactionData[transactionId];\n const amountFiat = transactionData?.fiatPayment?.amountFiat;\n const walletAddress = transaction.txParams.from as Hex;\n const requiredTokens = getRequiredTokens(transactionData?.tokens);\n const fiatAsset = deriveFiatAssetForFiatPayment(transaction);\n\n if (\n !amountFiat ||\n !fiatPaymentMethod ||\n !requiredTokens.length ||\n !fiatAsset\n ) {\n return [];\n }\n\n try {\n if (requiredTokens.length > 1) {\n throw new Error(\n 'Multiple required tokens not supported for fiat strategy',\n );\n }\n\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 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 relayTotalFeeUsd = getRelayTotalFeeUsd(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 paymentMethods: [fiatPaymentMethod],\n relayTotalFeeUsd: relayTotalFeeUsd.toString(10),\n sourceAmountRaw: relayRequest.sourceTokenAmount,\n transactionId,\n });\n\n const quotes = await messenger.call('RampsController:getQuotes', {\n amount: adjustedAmount,\n paymentMethods: [fiatPaymentMethod],\n walletAddress,\n });\n\n log('Fetched ramps quotes', {\n rampsQuotesCount: quotes.success?.length ?? 0,\n transactionId,\n });\n\n const fiatQuote = pickBestFiatQuote(quotes);\n\n if (!fiatQuote) {\n throw new Error('No matching ramps quote found for selected provider');\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\n return [];\n}\n\nfunction getRequiredTokens(\n tokens?: TransactionPayRequiredToken[],\n): TransactionPayRequiredToken[] {\n return tokens?.filter((token) => !token.skipIfBalance) ?? [];\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 decimals: number;\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 sourceAmountRaw = computeRawFromFiatAmount(\n amountFiat,\n fiatAsset.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.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 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"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitFiatQuotes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Submit Fiat quotes.
|
|
6
|
+
*
|
|
7
|
+
* @param _request - Strategy execute request.
|
|
8
|
+
* @returns Empty transaction hash until fiat submit implementation is added.
|
|
9
|
+
*/
|
|
10
|
+
async function submitFiatQuotes(_request) {
|
|
11
|
+
return { transactionHash: undefined };
|
|
12
|
+
}
|
|
13
|
+
exports.submitFiatQuotes = submitFiatQuotes;
|
|
14
|
+
//# sourceMappingURL=fiat-submit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fiat-submit.cjs","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-submit.ts"],"names":[],"mappings":";;;AAGA;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CACpC,QAA8C;IAE9C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AACxC,CAAC;AAJD,4CAIC","sourcesContent":["import type { FiatQuote } from './types';\nimport type { PayStrategy, PayStrategyExecuteRequest } from '../../types';\n\n/**\n * Submit Fiat quotes.\n *\n * @param _request - Strategy execute request.\n * @returns Empty transaction hash until fiat submit implementation is added.\n */\nexport async function submitFiatQuotes(\n _request: PayStrategyExecuteRequest<FiatQuote>,\n): ReturnType<PayStrategy<FiatQuote>['execute']> {\n return { transactionHash: undefined };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FiatQuote } from "./types.cjs";
|
|
2
|
+
import type { PayStrategy, PayStrategyExecuteRequest } from "../../types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Submit Fiat quotes.
|
|
5
|
+
*
|
|
6
|
+
* @param _request - Strategy execute request.
|
|
7
|
+
* @returns Empty transaction hash until fiat submit implementation is added.
|
|
8
|
+
*/
|
|
9
|
+
export declare function submitFiatQuotes(_request: PayStrategyExecuteRequest<FiatQuote>): ReturnType<PayStrategy<FiatQuote>['execute']>;
|
|
10
|
+
//# sourceMappingURL=fiat-submit.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fiat-submit.d.cts","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-submit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAgB;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,wBAAoB;AAE1E;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,yBAAyB,CAAC,SAAS,CAAC,GAC7C,UAAU,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAE/C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FiatQuote } from "./types.mjs";
|
|
2
|
+
import type { PayStrategy, PayStrategyExecuteRequest } from "../../types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Submit Fiat quotes.
|
|
5
|
+
*
|
|
6
|
+
* @param _request - Strategy execute request.
|
|
7
|
+
* @returns Empty transaction hash until fiat submit implementation is added.
|
|
8
|
+
*/
|
|
9
|
+
export declare function submitFiatQuotes(_request: PayStrategyExecuteRequest<FiatQuote>): ReturnType<PayStrategy<FiatQuote>['execute']>;
|
|
10
|
+
//# sourceMappingURL=fiat-submit.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fiat-submit.d.mts","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-submit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAgB;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,wBAAoB;AAE1E;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,yBAAyB,CAAC,SAAS,CAAC,GAC7C,UAAU,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAE/C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Submit Fiat quotes.
|
|
3
|
+
*
|
|
4
|
+
* @param _request - Strategy execute request.
|
|
5
|
+
* @returns Empty transaction hash until fiat submit implementation is added.
|
|
6
|
+
*/
|
|
7
|
+
export async function submitFiatQuotes(_request) {
|
|
8
|
+
return { transactionHash: undefined };
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=fiat-submit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fiat-submit.mjs","sourceRoot":"","sources":["../../../src/strategy/fiat/fiat-submit.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAA8C;IAE9C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import type { FiatQuote } from './types';\nimport type { PayStrategy, PayStrategyExecuteRequest } from '../../types';\n\n/**\n * Submit Fiat quotes.\n *\n * @param _request - Strategy execute request.\n * @returns Empty transaction hash until fiat submit implementation is added.\n */\nexport async function submitFiatQuotes(\n _request: PayStrategyExecuteRequest<FiatQuote>,\n): ReturnType<PayStrategy<FiatQuote>['execute']> {\n return { transactionHash: undefined };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../src/strategy/fiat/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Quote, QuotesResponse } from '@metamask/ramps-controller';\n\nimport type { RelayQuote } from '../relay/types';\n\nexport type FiatQuote = {\n rampsQuote: Quote;\n relayQuote: RelayQuote;\n};\n\nexport type FiatQuotesResponse = QuotesResponse;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Quote, QuotesResponse } from "@metamask/ramps-controller";
|
|
2
|
+
import type { RelayQuote } from "../relay/types.cjs";
|
|
3
|
+
export type FiatQuote = {
|
|
4
|
+
rampsQuote: Quote;
|
|
5
|
+
relayQuote: RelayQuote;
|
|
6
|
+
};
|
|
7
|
+
export type FiatQuotesResponse = QuotesResponse;
|
|
8
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../src/strategy/fiat/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,mCAAmC;AAExE,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AAEjD,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,KAAK,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Quote, QuotesResponse } from "@metamask/ramps-controller";
|
|
2
|
+
import type { RelayQuote } from "../relay/types.mjs";
|
|
3
|
+
export type FiatQuote = {
|
|
4
|
+
rampsQuote: Quote;
|
|
5
|
+
relayQuote: RelayQuote;
|
|
6
|
+
};
|
|
7
|
+
export type FiatQuotesResponse = QuotesResponse;
|
|
8
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../../src/strategy/fiat/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,mCAAmC;AAExE,OAAO,KAAK,EAAE,UAAU,EAAE,2BAAuB;AAEjD,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,KAAK,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../src/strategy/fiat/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Quote, QuotesResponse } from '@metamask/ramps-controller';\n\nimport type { RelayQuote } from '../relay/types';\n\nexport type FiatQuote = {\n rampsQuote: Quote;\n relayQuote: RelayQuote;\n};\n\nexport type FiatQuotesResponse = QuotesResponse;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pickBestFiatQuote = exports.deriveFiatAssetForFiatPayment = void 0;
|
|
4
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
5
|
+
const constants_1 = require("./constants.cjs");
|
|
6
|
+
function deriveFiatAssetForFiatPayment(transaction) {
|
|
7
|
+
const transactionType = transaction?.type;
|
|
8
|
+
if (transactionType === transaction_controller_1.TransactionType.batch) {
|
|
9
|
+
const firstMatchingType = transaction.nestedTransactions?.[0]?.type;
|
|
10
|
+
if (firstMatchingType) {
|
|
11
|
+
return constants_1.FIAT_ASSET_ID_BY_TX_TYPE[firstMatchingType];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return constants_1.FIAT_ASSET_ID_BY_TX_TYPE[transactionType];
|
|
15
|
+
}
|
|
16
|
+
exports.deriveFiatAssetForFiatPayment = deriveFiatAssetForFiatPayment;
|
|
17
|
+
function pickBestFiatQuote(quotes) {
|
|
18
|
+
return quotes.success?.find(
|
|
19
|
+
// TODO: Implement provider selection logic; force Transak staging for now.
|
|
20
|
+
(quote) => quote.provider === '/providers/transak-native-staging');
|
|
21
|
+
}
|
|
22
|
+
exports.pickBestFiatQuote = pickBestFiatQuote;
|
|
23
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../src/strategy/fiat/utils.ts"],"names":[],"mappings":";;;AAIA,6EAG0C;AAE1C,+CAAgF;AAEhF,SAAgB,6BAA6B,CAC3C,WAA4B;IAE5B,MAAM,eAAe,GAAG,WAAW,EAAE,IAAI,CAAC;IAE1C,IAAI,eAAe,KAAK,wCAAe,CAAC,KAAK,EAAE,CAAC;QAC9C,MAAM,iBAAiB,GAAG,WAAW,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;QACpE,IAAI,iBAAiB,EAAE,CAAC;YACtB,OAAO,oCAAwB,CAAC,iBAAiB,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,OAAO,oCAAwB,CAAC,eAAkC,CAAC,CAAC;AACtE,CAAC;AAbD,sEAaC;AAED,SAAgB,iBAAiB,CAC/B,MAA2B;IAE3B,OAAO,MAAM,CAAC,OAAO,EAAE,IAAI;IACzB,2EAA2E;IAC3E,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,mCAAmC,CAClE,CAAC;AACJ,CAAC;AAPD,8CAOC","sourcesContent":["import type {\n Quote as RampsQuote,\n QuotesResponse as RampsQuotesResponse,\n} from '@metamask/ramps-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { FIAT_ASSET_ID_BY_TX_TYPE, TransactionPayFiatAsset } from './constants';\n\nexport function deriveFiatAssetForFiatPayment(\n transaction: TransactionMeta,\n): TransactionPayFiatAsset | undefined {\n const transactionType = transaction?.type;\n\n if (transactionType === TransactionType.batch) {\n const firstMatchingType = transaction.nestedTransactions?.[0]?.type;\n if (firstMatchingType) {\n return FIAT_ASSET_ID_BY_TX_TYPE[firstMatchingType];\n }\n }\n\n return FIAT_ASSET_ID_BY_TX_TYPE[transactionType as TransactionType];\n}\n\nexport function pickBestFiatQuote(\n quotes: RampsQuotesResponse,\n): RampsQuote | undefined {\n return quotes.success?.find(\n // TODO: Implement provider selection logic; force Transak staging for now.\n (quote) => quote.provider === '/providers/transak-native-staging',\n );\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Quote as RampsQuote, QuotesResponse as RampsQuotesResponse } from "@metamask/ramps-controller";
|
|
2
|
+
import { TransactionMeta } from "@metamask/transaction-controller";
|
|
3
|
+
import { TransactionPayFiatAsset } from "./constants.cjs";
|
|
4
|
+
export declare function deriveFiatAssetForFiatPayment(transaction: TransactionMeta): TransactionPayFiatAsset | undefined;
|
|
5
|
+
export declare function pickBestFiatQuote(quotes: RampsQuotesResponse): RampsQuote | undefined;
|
|
6
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../../src/strategy/fiat/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,IAAI,UAAU,EACnB,cAAc,IAAI,mBAAmB,EACtC,mCAAmC;AACpC,OAAO,EACL,eAAe,EAEhB,yCAAyC;AAE1C,OAAO,EAA4B,uBAAuB,EAAE,wBAAoB;AAEhF,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,eAAe,GAC3B,uBAAuB,GAAG,SAAS,CAWrC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,mBAAmB,GAC1B,UAAU,GAAG,SAAS,CAKxB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Quote as RampsQuote, QuotesResponse as RampsQuotesResponse } from "@metamask/ramps-controller";
|
|
2
|
+
import { TransactionMeta } from "@metamask/transaction-controller";
|
|
3
|
+
import { TransactionPayFiatAsset } from "./constants.mjs";
|
|
4
|
+
export declare function deriveFiatAssetForFiatPayment(transaction: TransactionMeta): TransactionPayFiatAsset | undefined;
|
|
5
|
+
export declare function pickBestFiatQuote(quotes: RampsQuotesResponse): RampsQuote | undefined;
|
|
6
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../../src/strategy/fiat/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,IAAI,UAAU,EACnB,cAAc,IAAI,mBAAmB,EACtC,mCAAmC;AACpC,OAAO,EACL,eAAe,EAEhB,yCAAyC;AAE1C,OAAO,EAA4B,uBAAuB,EAAE,wBAAoB;AAEhF,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,eAAe,GAC3B,uBAAuB,GAAG,SAAS,CAWrC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,mBAAmB,GAC1B,UAAU,GAAG,SAAS,CAKxB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
|
+
import { FIAT_ASSET_ID_BY_TX_TYPE } from "./constants.mjs";
|
|
3
|
+
export function deriveFiatAssetForFiatPayment(transaction) {
|
|
4
|
+
const transactionType = transaction?.type;
|
|
5
|
+
if (transactionType === TransactionType.batch) {
|
|
6
|
+
const firstMatchingType = transaction.nestedTransactions?.[0]?.type;
|
|
7
|
+
if (firstMatchingType) {
|
|
8
|
+
return FIAT_ASSET_ID_BY_TX_TYPE[firstMatchingType];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return FIAT_ASSET_ID_BY_TX_TYPE[transactionType];
|
|
12
|
+
}
|
|
13
|
+
export function pickBestFiatQuote(quotes) {
|
|
14
|
+
return quotes.success?.find(
|
|
15
|
+
// TODO: Implement provider selection logic; force Transak staging for now.
|
|
16
|
+
(quote) => quote.provider === '/providers/transak-native-staging');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../../src/strategy/fiat/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAE1C,OAAO,EAAE,wBAAwB,EAA2B,wBAAoB;AAEhF,MAAM,UAAU,6BAA6B,CAC3C,WAA4B;IAE5B,MAAM,eAAe,GAAG,WAAW,EAAE,IAAI,CAAC;IAE1C,IAAI,eAAe,KAAK,eAAe,CAAC,KAAK,EAAE,CAAC;QAC9C,MAAM,iBAAiB,GAAG,WAAW,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;QACpE,IAAI,iBAAiB,EAAE,CAAC;YACtB,OAAO,wBAAwB,CAAC,iBAAiB,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,OAAO,wBAAwB,CAAC,eAAkC,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAA2B;IAE3B,OAAO,MAAM,CAAC,OAAO,EAAE,IAAI;IACzB,2EAA2E;IAC3E,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,mCAAmC,CAClE,CAAC;AACJ,CAAC","sourcesContent":["import type {\n Quote as RampsQuote,\n QuotesResponse as RampsQuotesResponse,\n} from '@metamask/ramps-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { FIAT_ASSET_ID_BY_TX_TYPE, TransactionPayFiatAsset } from './constants';\n\nexport function deriveFiatAssetForFiatPayment(\n transaction: TransactionMeta,\n): TransactionPayFiatAsset | undefined {\n const transactionType = transaction?.type;\n\n if (transactionType === TransactionType.batch) {\n const firstMatchingType = transaction.nestedTransactions?.[0]?.type;\n if (firstMatchingType) {\n return FIAT_ASSET_ID_BY_TX_TYPE[firstMatchingType];\n }\n }\n\n return FIAT_ASSET_ID_BY_TX_TYPE[transactionType as TransactionType];\n}\n\nexport function pickBestFiatQuote(\n quotes: RampsQuotesResponse,\n): RampsQuote | undefined {\n return quotes.success?.find(\n // TODO: Implement provider selection logic; force Transak staging for now.\n (quote) => quote.provider === '/providers/transak-native-staging',\n );\n}\n"]}
|
|
@@ -204,7 +204,7 @@ export declare function getMessengerMock({ skipRegister, }?: {
|
|
|
204
204
|
appData: string;
|
|
205
205
|
appDataHash: string;
|
|
206
206
|
feeAmount: string;
|
|
207
|
-
kind: "
|
|
207
|
+
kind: "buy" | "sell";
|
|
208
208
|
partiallyFillable: boolean;
|
|
209
209
|
receiver?: string | undefined;
|
|
210
210
|
sellAmount?: string | undefined;
|
|
@@ -204,7 +204,7 @@ export declare function getMessengerMock({ skipRegister, }?: {
|
|
|
204
204
|
appData: string;
|
|
205
205
|
appDataHash: string;
|
|
206
206
|
feeAmount: string;
|
|
207
|
-
kind: "
|
|
207
|
+
kind: "buy" | "sell";
|
|
208
208
|
partiallyFillable: boolean;
|
|
209
209
|
receiver?: string | undefined;
|
|
210
210
|
sellAmount?: string | undefined;
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AssetsControllerGetStateForTransactionPayAction } from '@metamask/assets-controller';\nimport type {\n CurrencyRateControllerActions,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokensControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { AccountTrackerControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { ControllerGetStateAction } from '@metamask/base-controller';\nimport type { BridgeControllerActions } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type { BridgeStatusControllerActions } from '@metamask/bridge-status-controller';\nimport type { GasFeeControllerActions } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type {\n AuthorizationList,\n TransactionControllerAddTransactionBatchAction,\n TransactionControllerEstimateGasAction,\n TransactionControllerEstimateGasBatchAction,\n TransactionControllerUnapprovedTransactionAddedEvent,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransaction,\n TransactionControllerAddTransactionAction,\n TransactionControllerGetGasFeeTokensAction,\n TransactionControllerGetStateAction,\n TransactionControllerStateChangeEvent,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport type { CONTROLLER_NAME, TransactionPayStrategy } from './constants';\nimport type { TransactionPayControllerMethodActions } from './TransactionPayController-method-action-types';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AssetsControllerGetStateForTransactionPayAction\n | BridgeControllerActions\n | BridgeStatusControllerActions\n | CurrencyRateControllerActions\n | GasFeeControllerActions\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\n | RemoteFeatureFlagControllerGetStateAction\n | TokenBalancesControllerGetStateAction\n | TokenRatesControllerGetStateAction\n | TokensControllerGetStateAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerGetGasFeeTokensAction\n | TransactionControllerGetStateAction\n | TransactionControllerUpdateTransactionAction;\n\nexport type AllowedEvents =\n | BridgeStatusControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n */\n isPostQuote?: boolean;\n\n /**\n * Optional address to receive refunds if the Relay transaction fails.\n * When set, overrides the default refund recipient (EOA) in the Relay quote\n * request. Use this for post-quote flows where the user's funds originate\n * from a smart contract account (e.g. Predict Safe proxy) so that refunds\n * go back to that account rather than the EOA.\n */\n refundTo?: Hex;\n};\n\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\n/** Callback to update fiat payment state. */\nexport type TransactionFiatPaymentCallback = (\n fiatPayment: TransactionFiatPayment,\n) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerMethodActions;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Callback to select ordered PayStrategies for a transaction. */\n getStrategies?: (transaction: TransactionMeta) => TransactionPayStrategy[];\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Initial state of the controller. */\n state?: Partial<TransactionPayControllerState>;\n};\n\n/** State of the TransactionPayController. */\nexport type TransactionPayControllerState = {\n /** State relating to each transaction, keyed by transaction ID. */\n transactionData: Record<string, TransactionData>;\n};\n\n/** State relating to a single transaction. */\nexport type TransactionData = {\n /** Fiat payment method state. */\n fiatPayment?: TransactionFiatPayment;\n\n /** Whether quotes are currently being retrieved. */\n isLoading: boolean;\n\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n * Used when funds need to be moved after a transaction completes\n * (e.g., bridging output to a different token/chain).\n */\n isPostQuote?: boolean;\n\n /**\n * Optional address to receive refunds if the Relay transaction fails.\n * When set, overrides the default refund recipient (EOA) in the Relay quote\n * request.\n */\n refundTo?: Hex;\n\n /**\n * Token selected for the transaction.\n * - For standard flows (isPostQuote=false): This is the SOURCE/payment token\n * - For post-quote flows (isPostQuote=true): This is the DESTINATION token\n */\n paymentToken?: TransactionPaymentToken;\n\n /** Quotes retrieved for the transaction. */\n quotes?: TransactionPayQuote<Json>[];\n\n /** Timestamp of when quotes were last updated. */\n quotesLastUpdated?: number;\n\n /** Amounts of payment token required for each required token. */\n sourceAmounts?: TransactionPaySourceAmount[];\n\n /** Tokens required by the transaction. */\n tokens: TransactionPayRequiredToken[];\n\n /** Calculated totals for the transaction. */\n totals?: TransactionPayTotals;\n};\n\n/** Fiat payment state stored per transaction. */\nexport type TransactionFiatPayment = {\n /** Entered fiat amount for the selected payment method. */\n amountFiat?: string;\n\n /** Selected fiat payment method ID. */\n selectedPaymentMethodId?: string;\n};\n\n/** A token required by a transaction. */\nexport type TransactionPayRequiredToken = {\n /** Address of the required token. */\n address: Hex;\n\n /** Whether to allow quotes that return less than the minimum amount requested. */\n allowUnderMinimum: boolean;\n\n /** Amount required in the selected currency. */\n amountFiat: string;\n\n /** Amount required in a human-readable format factoring token decimals. */\n amountHuman: string;\n\n /** Amount required in atomic format without factoring token decimals. */\n amountRaw: string;\n\n /** Amount required in USD. */\n amountUsd: string;\n\n /** Balance of the required token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the required token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the required token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the required token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the required token. */\n chainId: Hex;\n\n /** Decimals of the required token. */\n decimals: number;\n\n /** Whether to skip transfer of this token if balance is already sufficient. */\n skipIfBalance: boolean;\n\n /** Symbol of the required token. */\n symbol: string;\n};\n\n/** Amount of payment token required by a required token. */\nexport type TransactionPaySourceAmount = {\n /** Amount of payment token required in the selected currency. */\n sourceAmountHuman: string;\n\n /** Amount of payment token required in atomic format without factoring token decimals. */\n sourceAmountRaw: string;\n\n /** Balance of the source token in atomic format (for post-quote flows). */\n sourceBalanceRaw?: string;\n\n /** Chain ID of the source token (for post-quote flows). */\n sourceChainId?: Hex;\n\n /** Address of the source token (for post-quote flows). */\n sourceTokenAddress?: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n};\n\n/** Source token used to pay for required tokens. */\nexport type TransactionPaymentToken = {\n /** Address of the payment token. */\n address: Hex;\n\n /** Balance of the payment token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the payment token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the payment token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the payment token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the payment token. */\n chainId: Hex;\n\n /** Decimals of the payment token. */\n decimals: number;\n\n /** Symbol of the payment token. */\n symbol: string;\n};\n\n/** Callback to update state for a single transaction. */\nexport type UpdateTransactionDataCallback = (\n /** ID of the transaction to update. */\n transactionId: string,\n /** Function that receives a draft of the transaction data to update. */\n fn: (data: Draft<TransactionData>) => void,\n) => void;\n\n/** Conversion rates from the native currency to other currencies. */\nexport type FiatRates = {\n /** Conversion rate for the native currency to the selected fiat currency. */\n fiatRate: string;\n\n /** Conversion rate for the native currency to USD. */\n usdRate: string;\n};\n\n/** Request for a quote to retrieve a required token. */\nexport type QuoteRequest = {\n /** Address of the user's account. */\n from: Hex;\n\n /** Whether the transaction is a maximum amount transaction. */\n isMaxAmount?: boolean;\n\n /** Whether this is a post-quote flow. */\n isPostQuote?: boolean;\n\n /**\n * Optional address to receive refunds if the Relay transaction fails.\n * When set, overrides the default refund recipient (EOA) in the Relay quote\n * request.\n */\n refundTo?: Hex;\n\n /** Balance of the source token in atomic format without factoring token decimals. */\n sourceBalanceRaw: string;\n\n /** Chain ID of the source token. */\n sourceChainId: Hex;\n\n /** Address of the source token. */\n sourceTokenAddress: Hex;\n\n /** Amount of the required token in atomic format without factoring token decimals. */\n sourceTokenAmount: string;\n\n /** Minimum amount required of the target token in atomic format without factoring token decimals. */\n targetAmountMinimum: string;\n\n /** Chain ID of the target token. */\n targetChainId: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n};\n\n/** Fees associated with a transaction pay quote. */\nexport type TransactionPayFees = {\n /** Whether a gas fee token is used to pay source network fees. */\n isSourceGasFeeToken?: boolean;\n\n /** Whether a gas fee token is used to pay target network fees. */\n isTargetGasFeeToken?: boolean;\n\n /** Fee charged by MetaMask. */\n metaMask: FiatValue;\n\n /** Fee charged by the quote provider. */\n provider: FiatValue;\n\n /** Network fee for transactions on the source network. */\n sourceNetwork: {\n estimate: Amount;\n max: Amount;\n };\n\n /** Network fee for transactions on the target network. */\n targetNetwork: FiatValue;\n};\n\n/** Quote returned to retrieve a required token using the payment token. */\nexport type TransactionPayQuote<OriginalQuote> = {\n /** Additional amount provided by the quote beyond the minimum requested. */\n dust: FiatValue;\n\n /** Duration estimated for the transaction to complete in seconds. */\n estimatedDuration: number;\n\n /** Fees associated with the transaction pay quote. */\n fees: TransactionPayFees;\n\n /** Raw quote data returned by the provider. */\n original: OriginalQuote;\n\n /** Associated quote request. */\n request: QuoteRequest;\n\n /** Amount of source token required. */\n sourceAmount: Amount;\n\n /** Name of the strategy used to retrieve the quote. */\n strategy: TransactionPayStrategy;\n\n /** Amount of target token provided. */\n targetAmount: FiatValue;\n};\n\n/** Request to get quotes for a transaction. */\nexport type PayStrategyGetQuotesRequest = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to submit quotes for a transaction. */\nexport type PayStrategyExecuteRequest<OriginalRequest> = {\n /** Callback to determine if the transaction is a smart transaction. */\n isSmartTransaction: (chainId: Hex) => boolean;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes to be submitted. */\n quotes: TransactionPayQuote<OriginalRequest>[];\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to get batch transactions for quotes. */\nexport type PayStrategyGetBatchRequest<OriginalQuote> = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes for required tokens. */\n quotes: TransactionPayQuote<OriginalQuote>[];\n};\n\n/** Request to get refresh interval for a specific strategy. */\nexport type PayStrategyGetRefreshIntervalRequest = {\n /** Chain ID of the source or payment token. */\n chainId: Hex;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n};\n\n/** Strategy used to obtain required tokens for a transaction. */\nexport type PayStrategy<OriginalQuote> = {\n /**\n * Check if the strategy supports the given request.\n * Defaults to true if not implemented.\n */\n supports?: (request: PayStrategyGetQuotesRequest) => boolean;\n\n /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\n\n /** Retrieve batch transactions for quotes, if supported by the strategy. */\n getBatchTransactions?: (\n request: PayStrategyGetBatchRequest<OriginalQuote>,\n ) => Promise<BatchTransaction[]>;\n\n /**\n * Retrieve refresh interval for the strategy, if applicable.\n * Defaults to 30 seconds.\n */\n getRefreshInterval?: (\n request: PayStrategyGetRefreshIntervalRequest,\n ) => Promise<number | undefined>;\n\n /** Execute or submit the quotes to obtain required tokens. */\n execute: (request: PayStrategyExecuteRequest<OriginalQuote>) => Promise<{\n transactionHash?: Hex;\n }>;\n};\n\n/** Single fiat value in alternate currencies. */\nexport type FiatValue = {\n /** Value in the selected fiat currency. */\n fiat: string;\n\n /** Value in USD. */\n usd: string;\n};\n\n/** Calculated totals for a target transaction and all quotes. */\nexport type TransactionPayTotals = {\n /** Total estimated duration for the target transaction and all quotes. */\n estimatedDuration: number;\n\n /** Total fees for the target transaction and all quotes. */\n fees: TransactionPayFees;\n\n /** Total amount of source token required. */\n sourceAmount: Amount;\n\n /** Total amount of target token provided. */\n targetAmount: FiatValue;\n\n /** Overall total cost for the target transaction and all quotes. */\n total: FiatValue;\n};\n\n/** Request to update the payment token for a transaction. */\nexport type UpdatePaymentTokenRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Address of the new payment token. */\n tokenAddress: Hex;\n\n /** Chain ID of the new payment token. */\n chainId: Hex;\n};\n\n/** Request to update fiat payment state for a transaction. */\nexport type UpdateFiatPaymentRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Callback to mutate fiat payment state. */\n callback: TransactionFiatPaymentCallback;\n};\n\n/** Callback to convert a transaction to a redeem delegation. */\nexport type GetDelegationTransactionCallback = ({\n transaction,\n}: {\n transaction: TransactionMeta;\n}) => Promise<{\n authorizationList?: AuthorizationList;\n data: Hex;\n to: Hex;\n value: Hex;\n}>;\n\n/** Single amount in alternate formats. */\nexport type Amount = FiatValue & {\n /** Amount in human-readable format factoring token decimals. */\n human: string;\n\n /** Amount in atomic format without factoring token decimals. */\n raw: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AssetsControllerGetStateForTransactionPayAction } from '@metamask/assets-controller';\nimport type {\n CurrencyRateControllerActions,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokensControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { AccountTrackerControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { ControllerGetStateAction } from '@metamask/base-controller';\nimport type { BridgeControllerActions } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type { BridgeStatusControllerActions } from '@metamask/bridge-status-controller';\nimport type { GasFeeControllerActions } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';\nimport type { RampsControllerGetQuotesAction } from '@metamask/ramps-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type {\n AuthorizationList,\n TransactionControllerAddTransactionBatchAction,\n TransactionControllerEstimateGasAction,\n TransactionControllerEstimateGasBatchAction,\n TransactionControllerUnapprovedTransactionAddedEvent,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransaction,\n TransactionControllerAddTransactionAction,\n TransactionControllerGetGasFeeTokensAction,\n TransactionControllerGetStateAction,\n TransactionControllerStateChangeEvent,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport type { CONTROLLER_NAME, TransactionPayStrategy } from './constants';\nimport type { TransactionPayControllerMethodActions } from './TransactionPayController-method-action-types';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AssetsControllerGetStateForTransactionPayAction\n | BridgeControllerActions\n | BridgeStatusControllerActions\n | CurrencyRateControllerActions\n | GasFeeControllerActions\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\n | RampsControllerGetQuotesAction\n | RemoteFeatureFlagControllerGetStateAction\n | TokenBalancesControllerGetStateAction\n | TokenRatesControllerGetStateAction\n | TokensControllerGetStateAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerGetGasFeeTokensAction\n | TransactionControllerGetStateAction\n | TransactionControllerUpdateTransactionAction;\n\nexport type AllowedEvents =\n | BridgeStatusControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n */\n isPostQuote?: boolean;\n\n /**\n * Optional address to receive refunds if the Relay transaction fails.\n * When set, overrides the default refund recipient (EOA) in the Relay quote\n * request. Use this for post-quote flows where the user's funds originate\n * from a smart contract account (e.g. Predict Safe proxy) so that refunds\n * go back to that account rather than the EOA.\n */\n refundTo?: Hex;\n};\n\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\n/** Callback to update fiat payment state. */\nexport type TransactionFiatPaymentCallback = (\n fiatPayment: TransactionFiatPayment,\n) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerMethodActions;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Callback to select ordered PayStrategies for a transaction. */\n getStrategies?: (transaction: TransactionMeta) => TransactionPayStrategy[];\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Initial state of the controller. */\n state?: Partial<TransactionPayControllerState>;\n};\n\n/** State of the TransactionPayController. */\nexport type TransactionPayControllerState = {\n /** State relating to each transaction, keyed by transaction ID. */\n transactionData: Record<string, TransactionData>;\n};\n\n/** State relating to a single transaction. */\nexport type TransactionData = {\n /** Fiat payment method state. */\n fiatPayment?: TransactionFiatPayment;\n\n /** Whether quotes are currently being retrieved. */\n isLoading: boolean;\n\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n * Used when funds need to be moved after a transaction completes\n * (e.g., bridging output to a different token/chain).\n */\n isPostQuote?: boolean;\n\n /**\n * Optional address to receive refunds if the Relay transaction fails.\n * When set, overrides the default refund recipient (EOA) in the Relay quote\n * request.\n */\n refundTo?: Hex;\n\n /**\n * Token selected for the transaction.\n * - For standard flows (isPostQuote=false): This is the SOURCE/payment token\n * - For post-quote flows (isPostQuote=true): This is the DESTINATION token\n */\n paymentToken?: TransactionPaymentToken;\n\n /** Quotes retrieved for the transaction. */\n quotes?: TransactionPayQuote<Json>[];\n\n /** Timestamp of when quotes were last updated. */\n quotesLastUpdated?: number;\n\n /** Amounts of payment token required for each required token. */\n sourceAmounts?: TransactionPaySourceAmount[];\n\n /** Tokens required by the transaction. */\n tokens: TransactionPayRequiredToken[];\n\n /** Calculated totals for the transaction. */\n totals?: TransactionPayTotals;\n};\n\n/** Fiat payment state stored per transaction. */\nexport type TransactionFiatPayment = {\n /** Entered fiat amount for the selected payment method. */\n amountFiat?: string;\n\n /** Selected fiat payment method ID. */\n selectedPaymentMethodId?: string;\n};\n\n/** A token required by a transaction. */\nexport type TransactionPayRequiredToken = {\n /** Address of the required token. */\n address: Hex;\n\n /** Whether to allow quotes that return less than the minimum amount requested. */\n allowUnderMinimum: boolean;\n\n /** Amount required in the selected currency. */\n amountFiat: string;\n\n /** Amount required in a human-readable format factoring token decimals. */\n amountHuman: string;\n\n /** Amount required in atomic format without factoring token decimals. */\n amountRaw: string;\n\n /** Amount required in USD. */\n amountUsd: string;\n\n /** Balance of the required token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the required token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the required token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the required token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the required token. */\n chainId: Hex;\n\n /** Decimals of the required token. */\n decimals: number;\n\n /** Whether to skip transfer of this token if balance is already sufficient. */\n skipIfBalance: boolean;\n\n /** Symbol of the required token. */\n symbol: string;\n};\n\n/** Amount of payment token required by a required token. */\nexport type TransactionPaySourceAmount = {\n /** Amount of payment token required in the selected currency. */\n sourceAmountHuman: string;\n\n /** Amount of payment token required in atomic format without factoring token decimals. */\n sourceAmountRaw: string;\n\n /** Balance of the source token in atomic format (for post-quote flows). */\n sourceBalanceRaw?: string;\n\n /** Chain ID of the source token (for post-quote flows). */\n sourceChainId?: Hex;\n\n /** Address of the source token (for post-quote flows). */\n sourceTokenAddress?: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n};\n\n/** Source token used to pay for required tokens. */\nexport type TransactionPaymentToken = {\n /** Address of the payment token. */\n address: Hex;\n\n /** Balance of the payment token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the payment token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the payment token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the payment token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the payment token. */\n chainId: Hex;\n\n /** Decimals of the payment token. */\n decimals: number;\n\n /** Symbol of the payment token. */\n symbol: string;\n};\n\n/** Callback to update state for a single transaction. */\nexport type UpdateTransactionDataCallback = (\n /** ID of the transaction to update. */\n transactionId: string,\n /** Function that receives a draft of the transaction data to update. */\n fn: (data: Draft<TransactionData>) => void,\n) => void;\n\n/** Conversion rates from the native currency to other currencies. */\nexport type FiatRates = {\n /** Conversion rate for the native currency to the selected fiat currency. */\n fiatRate: string;\n\n /** Conversion rate for the native currency to USD. */\n usdRate: string;\n};\n\n/** Request for a quote to retrieve a required token. */\nexport type QuoteRequest = {\n /** Address of the user's account. */\n from: Hex;\n\n /** Whether the transaction is a maximum amount transaction. */\n isMaxAmount?: boolean;\n\n /** Whether this is a post-quote flow. */\n isPostQuote?: boolean;\n\n /**\n * Optional address to receive refunds if the Relay transaction fails.\n * When set, overrides the default refund recipient (EOA) in the Relay quote\n * request.\n */\n refundTo?: Hex;\n\n /** Balance of the source token in atomic format without factoring token decimals. */\n sourceBalanceRaw: string;\n\n /** Chain ID of the source token. */\n sourceChainId: Hex;\n\n /** Address of the source token. */\n sourceTokenAddress: Hex;\n\n /** Amount of the required token in atomic format without factoring token decimals. */\n sourceTokenAmount: string;\n\n /** Minimum amount required of the target token in atomic format without factoring token decimals. */\n targetAmountMinimum: string;\n\n /** Chain ID of the target token. */\n targetChainId: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n};\n\n/** Fees associated with a transaction pay quote. */\nexport type TransactionPayFees = {\n /** Whether a gas fee token is used to pay source network fees. */\n isSourceGasFeeToken?: boolean;\n\n /** Whether a gas fee token is used to pay target network fees. */\n isTargetGasFeeToken?: boolean;\n\n /** Fee charged by MetaMask. */\n metaMask: FiatValue;\n\n /** Fee charged by the quote provider. */\n provider: FiatValue;\n\n /** Fee charged by fiat on-ramp provider (breakdown of the provider total). */\n providerFiat?: FiatValue;\n\n /** Network fee for transactions on the source network. */\n sourceNetwork: {\n estimate: Amount;\n max: Amount;\n };\n\n /** Network fee for transactions on the target network. */\n targetNetwork: FiatValue;\n};\n\n/** Quote returned to retrieve a required token using the payment token. */\nexport type TransactionPayQuote<OriginalQuote> = {\n /** Additional amount provided by the quote beyond the minimum requested. */\n dust: FiatValue;\n\n /** Duration estimated for the transaction to complete in seconds. */\n estimatedDuration: number;\n\n /** Fees associated with the transaction pay quote. */\n fees: TransactionPayFees;\n\n /** Raw quote data returned by the provider. */\n original: OriginalQuote;\n\n /** Associated quote request. */\n request: QuoteRequest;\n\n /** Amount of source token required. */\n sourceAmount: Amount;\n\n /** Name of the strategy used to retrieve the quote. */\n strategy: TransactionPayStrategy;\n\n /** Amount of target token provided. */\n targetAmount: FiatValue;\n};\n\n/** Request to get quotes for a transaction. */\nexport type PayStrategyGetQuotesRequest = {\n /** Selected fiat payment method ID, if applicable. */\n fiatPaymentMethod?: string;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to submit quotes for a transaction. */\nexport type PayStrategyExecuteRequest<OriginalRequest> = {\n /** Callback to determine if the transaction is a smart transaction. */\n isSmartTransaction: (chainId: Hex) => boolean;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes to be submitted. */\n quotes: TransactionPayQuote<OriginalRequest>[];\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to get batch transactions for quotes. */\nexport type PayStrategyGetBatchRequest<OriginalQuote> = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes for required tokens. */\n quotes: TransactionPayQuote<OriginalQuote>[];\n};\n\n/** Request to get refresh interval for a specific strategy. */\nexport type PayStrategyGetRefreshIntervalRequest = {\n /** Chain ID of the source or payment token. */\n chainId: Hex;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n};\n\n/** Strategy used to obtain required tokens for a transaction. */\nexport type PayStrategy<OriginalQuote> = {\n /**\n * Check if the strategy supports the given request.\n * Defaults to true if not implemented.\n */\n supports?: (request: PayStrategyGetQuotesRequest) => boolean;\n\n /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\n\n /** Retrieve batch transactions for quotes, if supported by the strategy. */\n getBatchTransactions?: (\n request: PayStrategyGetBatchRequest<OriginalQuote>,\n ) => Promise<BatchTransaction[]>;\n\n /**\n * Retrieve refresh interval for the strategy, if applicable.\n * Defaults to 30 seconds.\n */\n getRefreshInterval?: (\n request: PayStrategyGetRefreshIntervalRequest,\n ) => Promise<number | undefined>;\n\n /** Execute or submit the quotes to obtain required tokens. */\n execute: (request: PayStrategyExecuteRequest<OriginalQuote>) => Promise<{\n transactionHash?: Hex;\n }>;\n};\n\n/** Single fiat value in alternate currencies. */\nexport type FiatValue = {\n /** Value in the selected fiat currency. */\n fiat: string;\n\n /** Value in USD. */\n usd: string;\n};\n\n/** Calculated totals for a target transaction and all quotes. */\nexport type TransactionPayTotals = {\n /** Total estimated duration for the target transaction and all quotes. */\n estimatedDuration: number;\n\n /** Total fees for the target transaction and all quotes. */\n fees: TransactionPayFees;\n\n /** Total amount of source token required. */\n sourceAmount: Amount;\n\n /** Total amount of target token provided. */\n targetAmount: FiatValue;\n\n /** Overall total cost for the target transaction and all quotes. */\n total: FiatValue;\n};\n\n/** Request to update the payment token for a transaction. */\nexport type UpdatePaymentTokenRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Address of the new payment token. */\n tokenAddress: Hex;\n\n /** Chain ID of the new payment token. */\n chainId: Hex;\n};\n\n/** Request to update fiat payment state for a transaction. */\nexport type UpdateFiatPaymentRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Callback to mutate fiat payment state. */\n callback: TransactionFiatPaymentCallback;\n};\n\n/** Callback to convert a transaction to a redeem delegation. */\nexport type GetDelegationTransactionCallback = ({\n transaction,\n}: {\n transaction: TransactionMeta;\n}) => Promise<{\n authorizationList?: AuthorizationList;\n data: Hex;\n to: Hex;\n value: Hex;\n}>;\n\n/** Single amount in alternate formats. */\nexport type Amount = FiatValue & {\n /** Amount in human-readable format factoring token decimals. */\n human: string;\n\n /** Amount in atomic format without factoring token decimals. */\n raw: string;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -12,6 +12,7 @@ import type { GasFeeControllerActions } from "@metamask/gas-fee-controller";
|
|
|
12
12
|
import type { Messenger } from "@metamask/messenger";
|
|
13
13
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction } from "@metamask/network-controller";
|
|
14
14
|
import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
15
|
+
import type { RampsControllerGetQuotesAction } from "@metamask/ramps-controller";
|
|
15
16
|
import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
|
|
16
17
|
import type { AuthorizationList, TransactionControllerAddTransactionBatchAction, TransactionControllerEstimateGasAction, TransactionControllerEstimateGasBatchAction, TransactionControllerUnapprovedTransactionAddedEvent } from "@metamask/transaction-controller";
|
|
17
18
|
import type { BatchTransaction, TransactionControllerAddTransactionAction, TransactionControllerGetGasFeeTokensAction, TransactionControllerGetStateAction, TransactionControllerStateChangeEvent, TransactionControllerUpdateTransactionAction, TransactionMeta } from "@metamask/transaction-controller";
|
|
@@ -19,7 +20,7 @@ import type { Hex, Json } from "@metamask/utils";
|
|
|
19
20
|
import type { Draft } from "immer";
|
|
20
21
|
import type { CONTROLLER_NAME, TransactionPayStrategy } from "./constants.cjs";
|
|
21
22
|
import type { TransactionPayControllerMethodActions } from "./TransactionPayController-method-action-types.cjs";
|
|
22
|
-
export type AllowedActions = AccountTrackerControllerGetStateAction | AssetsControllerGetStateForTransactionPayAction | BridgeControllerActions | BridgeStatusControllerActions | CurrencyRateControllerActions | GasFeeControllerActions | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction | RemoteFeatureFlagControllerGetStateAction | TokenBalancesControllerGetStateAction | TokenRatesControllerGetStateAction | TokensControllerGetStateAction | TransactionControllerAddTransactionAction | TransactionControllerAddTransactionBatchAction | TransactionControllerEstimateGasAction | TransactionControllerEstimateGasBatchAction | TransactionControllerGetGasFeeTokensAction | TransactionControllerGetStateAction | TransactionControllerUpdateTransactionAction;
|
|
23
|
+
export type AllowedActions = AccountTrackerControllerGetStateAction | AssetsControllerGetStateForTransactionPayAction | BridgeControllerActions | BridgeStatusControllerActions | CurrencyRateControllerActions | GasFeeControllerActions | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction | RampsControllerGetQuotesAction | RemoteFeatureFlagControllerGetStateAction | TokenBalancesControllerGetStateAction | TokenRatesControllerGetStateAction | TokensControllerGetStateAction | TransactionControllerAddTransactionAction | TransactionControllerAddTransactionBatchAction | TransactionControllerEstimateGasAction | TransactionControllerEstimateGasBatchAction | TransactionControllerGetGasFeeTokensAction | TransactionControllerGetStateAction | TransactionControllerUpdateTransactionAction;
|
|
23
24
|
export type AllowedEvents = BridgeStatusControllerStateChangeEvent | TransactionControllerStateChangeEvent | TransactionControllerUnapprovedTransactionAddedEvent;
|
|
24
25
|
export type TransactionPayControllerGetStateAction = ControllerGetStateAction<typeof CONTROLLER_NAME, TransactionPayControllerState>;
|
|
25
26
|
/** Configurable properties of a transaction. */
|
|
@@ -230,6 +231,8 @@ export type TransactionPayFees = {
|
|
|
230
231
|
metaMask: FiatValue;
|
|
231
232
|
/** Fee charged by the quote provider. */
|
|
232
233
|
provider: FiatValue;
|
|
234
|
+
/** Fee charged by fiat on-ramp provider (breakdown of the provider total). */
|
|
235
|
+
providerFiat?: FiatValue;
|
|
233
236
|
/** Network fee for transactions on the source network. */
|
|
234
237
|
sourceNetwork: {
|
|
235
238
|
estimate: Amount;
|
|
@@ -259,6 +262,8 @@ export type TransactionPayQuote<OriginalQuote> = {
|
|
|
259
262
|
};
|
|
260
263
|
/** Request to get quotes for a transaction. */
|
|
261
264
|
export type PayStrategyGetQuotesRequest = {
|
|
265
|
+
/** Selected fiat payment method ID, if applicable. */
|
|
266
|
+
fiatPaymentMethod?: string;
|
|
262
267
|
/** Controller messenger. */
|
|
263
268
|
messenger: TransactionPayControllerMessenger;
|
|
264
269
|
/** Quote requests for required tokens. */
|