@metamask-previews/transaction-pay-controller 16.4.1-preview-3b760ee09 → 16.4.1-preview-d8a0c2fc5
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 +9 -0
- package/dist/strategy/across/across-quotes.cjs +42 -8
- 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 +42 -8
- package/dist/strategy/across/across-quotes.mjs.map +1 -1
- package/dist/tests/messenger-mock.d.cts +8 -1
- package/dist/tests/messenger-mock.d.cts.map +1 -1
- package/dist/tests/messenger-mock.d.mts +8 -1
- package/dist/tests/messenger-mock.d.mts.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +0 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +0 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Add `AppMetadataControllerGetStateAction` and `AssetsControllerGetStateForTransactionPayAction` to the `AllowedActions` messenger type ([#8163](https://github.com/MetaMask/core/pull/8163))
|
|
12
13
|
- Support gasless Relay deposits via `execute` endpoint ([#8133](https://github.com/MetaMask/core/pull/8133))
|
|
14
|
+
- Build Across post-swap transfer actions for `predictDeposit` quotes so Predict deposits can bridge swapped output into the destination proxy wallet ([#8159](https://github.com/MetaMask/core/pull/8159))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- `getTokenBalance`, `getTokenInfo`, and `getTokenFiatRate` now source token metadata, balances, and pricing from `AssetsController:getStateForTransactionPay` when the `assetsUnifyState` remote feature flag is enabled, falling back to individual controller state calls otherwise ([#8163](https://github.com/MetaMask/core/pull/8163))
|
|
19
|
+
- Bump `@metamask/assets-controllers` from `^100.2.0` to `^100.2.1` ([#8162](https://github.com/MetaMask/core/pull/8162))
|
|
20
|
+
- Bump `@metamask/bridge-controller` from `^69.0.0` to `^69.1.0` ([#8162](https://github.com/MetaMask/core/pull/8162), [#8168](https://github.com/MetaMask/core/pull/8168))
|
|
21
|
+
- Bump `@metamask/bridge-status-controller` from `^68.0.1` to `^68.1.0` ([#8162](https://github.com/MetaMask/core/pull/8162), [#8168](https://github.com/MetaMask/core/pull/8168))
|
|
13
22
|
|
|
14
23
|
## [16.4.1]
|
|
15
24
|
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAcrossQuotes = void 0;
|
|
4
4
|
const abi_1 = require("@ethersproject/abi");
|
|
5
5
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
6
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
6
7
|
const utils_1 = require("@metamask/utils");
|
|
7
8
|
const bignumber_js_1 = require("bignumber.js");
|
|
8
9
|
const constants_1 = require("../../constants.cjs");
|
|
@@ -14,7 +15,7 @@ const token_1 = require("../../utils/token.cjs");
|
|
|
14
15
|
const constants_2 = require("../relay/constants.cjs");
|
|
15
16
|
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'across-strategy');
|
|
16
17
|
const TOKEN_TRANSFER_INTERFACE = new abi_1.Interface([
|
|
17
|
-
'function transfer(address to, uint256
|
|
18
|
+
'function transfer(address to, uint256 value)',
|
|
18
19
|
]);
|
|
19
20
|
const UNSUPPORTED_AUTHORIZATION_LIST_ERROR = 'Across does not support type-4/EIP-7702 authorization lists yet';
|
|
20
21
|
const UNSUPPORTED_DESTINATION_ERROR = 'Across only supports transfer-style destination flows at the moment';
|
|
@@ -52,8 +53,9 @@ async function getSingleQuote(request, fullRequest) {
|
|
|
52
53
|
const slippageDecimal = (0, feature_flags_1.getSlippage)(messenger, sourceChainId, sourceTokenAddress);
|
|
53
54
|
const amount = isMaxAmount ? sourceTokenAmount : targetAmountMinimum;
|
|
54
55
|
const tradeType = isMaxAmount ? 'exactInput' : 'exactOutput';
|
|
55
|
-
const
|
|
56
|
+
const destination = getAcrossDestination(transaction, request);
|
|
56
57
|
const quote = await requestAcrossApproval({
|
|
58
|
+
actions: destination.actions,
|
|
57
59
|
amount,
|
|
58
60
|
apiBase: config.across.apiBase,
|
|
59
61
|
depositor: from,
|
|
@@ -61,7 +63,7 @@ async function getSingleQuote(request, fullRequest) {
|
|
|
61
63
|
inputToken: sourceTokenAddress,
|
|
62
64
|
originChainId: sourceChainId,
|
|
63
65
|
outputToken: targetTokenAddress,
|
|
64
|
-
recipient,
|
|
66
|
+
recipient: destination.recipient,
|
|
65
67
|
slippage: slippageDecimal,
|
|
66
68
|
tradeType,
|
|
67
69
|
});
|
|
@@ -75,7 +77,7 @@ async function getSingleQuote(request, fullRequest) {
|
|
|
75
77
|
return await normalizeQuote(originalQuote, request, fullRequest);
|
|
76
78
|
}
|
|
77
79
|
async function requestAcrossApproval(request) {
|
|
78
|
-
const { amount, apiBase, depositor, destinationChainId, inputToken, originChainId, outputToken, recipient, slippage, tradeType, } = request;
|
|
80
|
+
const { actions, amount, apiBase, depositor, destinationChainId, inputToken, originChainId, outputToken, recipient, slippage, tradeType, } = request;
|
|
79
81
|
const params = new URLSearchParams();
|
|
80
82
|
params.set('tradeType', tradeType);
|
|
81
83
|
params.set('amount', amount);
|
|
@@ -88,7 +90,7 @@ async function requestAcrossApproval(request) {
|
|
|
88
90
|
if (slippage !== undefined) {
|
|
89
91
|
params.set('slippage', String(slippage));
|
|
90
92
|
}
|
|
91
|
-
const body = { actions
|
|
93
|
+
const body = { actions };
|
|
92
94
|
const url = `${apiBase}/swap/approval?${params.toString()}`;
|
|
93
95
|
const options = {
|
|
94
96
|
body: JSON.stringify(body),
|
|
@@ -101,21 +103,53 @@ async function requestAcrossApproval(request) {
|
|
|
101
103
|
const response = await (0, controller_utils_1.successfulFetch)(url, options);
|
|
102
104
|
return (await response.json());
|
|
103
105
|
}
|
|
104
|
-
function
|
|
106
|
+
function getAcrossDestination(transaction, request) {
|
|
105
107
|
const { txParams } = transaction;
|
|
106
108
|
const { from } = request;
|
|
107
109
|
const transferData = getTransferData(transaction);
|
|
108
110
|
if (transferData) {
|
|
109
|
-
|
|
111
|
+
const transferRecipient = getTransferRecipient(transferData);
|
|
112
|
+
if (transaction.type === transaction_controller_1.TransactionType.predictDeposit) {
|
|
113
|
+
return {
|
|
114
|
+
actions: [buildAcrossTransferAction(transferRecipient, request)],
|
|
115
|
+
recipient: from,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
actions: [],
|
|
120
|
+
recipient: transferRecipient,
|
|
121
|
+
};
|
|
110
122
|
}
|
|
111
123
|
const data = txParams?.data;
|
|
112
124
|
const hasNoData = data === undefined || data === '0x';
|
|
113
125
|
const nestedCalldata = getNestedCalldata(transaction);
|
|
114
126
|
if (hasNoData && nestedCalldata.length === 0) {
|
|
115
|
-
return
|
|
127
|
+
return {
|
|
128
|
+
actions: [],
|
|
129
|
+
recipient: from,
|
|
130
|
+
};
|
|
116
131
|
}
|
|
117
132
|
throw new Error(UNSUPPORTED_DESTINATION_ERROR);
|
|
118
133
|
}
|
|
134
|
+
function buildAcrossTransferAction(transferRecipient, request) {
|
|
135
|
+
return {
|
|
136
|
+
args: [
|
|
137
|
+
{
|
|
138
|
+
populateDynamically: false,
|
|
139
|
+
value: transferRecipient,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
balanceSourceToken: request.targetTokenAddress,
|
|
143
|
+
populateDynamically: true,
|
|
144
|
+
value: '0',
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
functionSignature: 'function transfer(address to, uint256 value)',
|
|
148
|
+
isNativeTransfer: false,
|
|
149
|
+
target: request.targetTokenAddress,
|
|
150
|
+
value: '0',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
119
153
|
function getTransferData(transaction) {
|
|
120
154
|
const { nestedTransactions, txParams } = transaction;
|
|
121
155
|
const nestedTransferData = nestedTransactions?.find((nestedTx) => nestedTx.data?.startsWith(constants_2.TOKEN_TRANSFER_FOUR_BYTE))?.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"across-quotes.cjs","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,iEAAoE;AAGpE,2CAAqD;AACrD,+CAAyC;AAQzC,mDAAyD;AACzD,6CAA6C;AAS7C,qDAAsE;AACtE,iEAAgF;AAChF,6CAAqE;AACrE,iDAAqD;AACrD,sDAA8D;AAE9D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,iBAAiB,CAAC,CAAC;AAEjE,MAAM,wBAAwB,GAAG,IAAI,eAAS,CAAC;IAC7C,+CAA+C;CAChD,CAAC,CAAC;AAEH,MAAM,oCAAoC,GACxC,iEAAiE,CAAC;AACpE,MAAM,6BAA6B,GACjC,qEAAqE,CAAC;AAIxE;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CACnC,OAAoC;IAEpC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAEjC,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CACxC,CAAC,aAAa,EAAE,EAAE,CAChB,aAAa,CAAC,WAAW,KAAK,IAAI;YAClC,CAAC,aAAa,CAAC,mBAAmB,KAAK,SAAS;gBAC9C,aAAa,CAAC,mBAAmB,KAAK,GAAG,CAAC,CAC/C,CAAC;QAEF,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,OAAO,CA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AE,MAAM,CAAC,YAAY;YACjC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;YACjD,SAAS;SACV,CAAC;KACH,CAAC,CAAC;IAEH,OAAO;QACL,aAAa,EAAE;YACb,QAAQ;YACR,GAAG;SACJ;QACD,SAAS,EAAE;YACT,QAAQ,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7C,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,GAAG,EAAE,GAAG,CAAC,GAAG;aACb,CAAC,CAAC;YACH,IAAI,EAAE;gBACJ,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,GAAG,EAAE,OAAO,CAAC,GAAG;aACjB;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,GAAY;IAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QACpC,CAAC,CAAC,IAAI,wBAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACjC,CAAC,CAAC,IAAI,wBAAS,CAAC,GAAG,CAAC,CAAC;IAEvB,IACE,CAAC,SAAS,CAAC,QAAQ,EAAE;QACrB,SAAS,CAAC,KAAK,EAAE;QACjB,CAAC,SAAS,CAAC,SAAS,EAAE;QACtB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAChB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { successfulFetch, toHex } from '@metamask/controller-utils';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n AcrossActionRequestBody,\n AcrossGasLimits,\n AcrossQuote,\n AcrossSwapApprovalResponse,\n} from './types';\nimport { TransactionPayStrategy } from '../../constants';\nimport { projectLogger } from '../../logger';\nimport type {\n Amount,\n FiatRates,\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\nimport { getFiatValueFromUsd, sumAmounts } from '../../utils/amounts';\nimport { getPayStrategiesConfig, getSlippage } from '../../utils/feature-flags';\nimport { calculateGasCost, estimateGasLimit } from '../../utils/gas';\nimport { getTokenFiatRate } from '../../utils/token';\nimport { TOKEN_TRANSFER_FOUR_BYTE } from '../relay/constants';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\n\nconst TOKEN_TRANSFER_INTERFACE = new Interface([\n 'function transfer(address to, uint256 amount)',\n]);\n\nconst UNSUPPORTED_AUTHORIZATION_LIST_ERROR =\n 'Across does not support type-4/EIP-7702 authorization lists yet';\nconst UNSUPPORTED_DESTINATION_ERROR =\n 'Across only supports transfer-style destination flows at the moment';\n\ntype AcrossQuoteWithoutMetaMask = Omit<AcrossQuote, 'metamask'>;\n\n/**\n * Fetch Across quotes.\n *\n * @param request - Request object.\n * @returns Array of quotes.\n */\nexport async function getAcrossQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>[]> {\n const { requests } = request;\n\n log('Fetching quotes', requests);\n\n try {\n const normalizedRequests = requests.filter(\n (singleRequest) =>\n singleRequest.isMaxAmount === true ||\n (singleRequest.targetAmountMinimum !== undefined &&\n singleRequest.targetAmountMinimum !== '0'),\n );\n\n if (normalizedRequests.length === 0) {\n return [];\n }\n\n if (request.transaction.txParams?.authorizationList?.length) {\n throw new Error(UNSUPPORTED_AUTHORIZATION_LIST_ERROR);\n }\n\n return await Promise.all(\n normalizedRequests.map((singleRequest) =>\n getSingleQuote(singleRequest, request),\n ),\n );\n } catch (error) {\n log('Error fetching quotes', { error });\n throw new Error(`Failed to fetch Across quotes: ${String(error)}`);\n }\n}\n\nasync function getSingleQuote(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger, transaction } = fullRequest;\n const {\n from,\n isMaxAmount,\n sourceChainId,\n sourceTokenAddress,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = request;\n\n const config = getPayStrategiesConfig(messenger);\n const slippageDecimal = getSlippage(\n messenger,\n sourceChainId,\n sourceTokenAddress,\n );\n\n const amount = isMaxAmount ? sourceTokenAmount : targetAmountMinimum;\n const tradeType = isMaxAmount ? 'exactInput' : 'exactOutput';\n const recipient = getAcrossRecipient(transaction, request);\n const quote = await requestAcrossApproval({\n amount,\n apiBase: config.across.apiBase,\n depositor: from,\n destinationChainId: targetChainId,\n inputToken: sourceTokenAddress,\n originChainId: sourceChainId,\n outputToken: targetTokenAddress,\n recipient,\n slippage: slippageDecimal,\n tradeType,\n });\n\n const originalQuote: AcrossQuoteWithoutMetaMask = {\n quote,\n request: {\n amount,\n tradeType,\n },\n };\n\n return await normalizeQuote(originalQuote, request, fullRequest);\n}\n\ntype AcrossApprovalRequest = {\n amount: string;\n apiBase: string;\n depositor: Hex;\n destinationChainId: Hex;\n inputToken: Hex;\n originChainId: Hex;\n outputToken: Hex;\n recipient: Hex;\n slippage?: number;\n tradeType: 'exactInput' | 'exactOutput';\n};\n\nasync function requestAcrossApproval(\n request: AcrossApprovalRequest,\n): Promise<AcrossSwapApprovalResponse> {\n const {\n amount,\n apiBase,\n depositor,\n destinationChainId,\n inputToken,\n originChainId,\n outputToken,\n recipient,\n slippage,\n tradeType,\n } = request;\n\n const params = new URLSearchParams();\n params.set('tradeType', tradeType);\n params.set('amount', amount);\n params.set('inputToken', inputToken);\n params.set('outputToken', outputToken);\n params.set('originChainId', String(parseInt(originChainId, 16)));\n params.set('destinationChainId', String(parseInt(destinationChainId, 16)));\n params.set('depositor', depositor);\n params.set('recipient', recipient);\n\n if (slippage !== undefined) {\n params.set('slippage', String(slippage));\n }\n\n const body: AcrossActionRequestBody = { actions: [] };\n const url = `${apiBase}/swap/approval?${params.toString()}`;\n const options: RequestInit = {\n body: JSON.stringify(body),\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n };\n const response = await successfulFetch(url, options);\n\n return (await response.json()) as AcrossSwapApprovalResponse;\n}\n\nfunction getAcrossRecipient(\n transaction: TransactionMeta,\n request: QuoteRequest,\n): Hex {\n const { txParams } = transaction;\n const { from } = request;\n const transferData = getTransferData(transaction);\n\n if (transferData) {\n return getTransferRecipient(transferData);\n }\n\n const data = txParams?.data as Hex | undefined;\n const hasNoData = data === undefined || data === '0x';\n const nestedCalldata = getNestedCalldata(transaction);\n\n if (hasNoData && nestedCalldata.length === 0) {\n return from;\n }\n\n throw new Error(UNSUPPORTED_DESTINATION_ERROR);\n}\n\nfunction getTransferData(transaction: TransactionMeta): Hex | undefined {\n const { nestedTransactions, txParams } = transaction;\n\n const nestedTransferData = nestedTransactions?.find(\n (nestedTx: { data?: Hex }) =>\n nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE),\n )?.data;\n\n const data = txParams?.data as Hex | undefined;\n const tokenTransferData = data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE)\n ? data\n : undefined;\n\n return nestedTransferData ?? tokenTransferData;\n}\n\nfunction getNestedCalldata(transaction: TransactionMeta): Hex[] {\n return (transaction.nestedTransactions ?? [])\n .map((nestedTx: { data?: Hex }) => nestedTx.data)\n .filter(\n (data: Hex | undefined): data is Hex =>\n data !== undefined && data !== '0x',\n );\n}\n\nfunction getTransferRecipient(data: Hex): Hex {\n return TOKEN_TRANSFER_INTERFACE.decodeFunctionData(\n 'transfer',\n data,\n ).to.toLowerCase() as Hex;\n}\n\nasync function normalizeQuote(\n original: AcrossQuoteWithoutMetaMask,\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger } = fullRequest;\n const { quote } = original;\n\n const { usdToFiatRate, sourceFiatRate, targetFiatRate } = getFiatRates(\n messenger,\n quote,\n );\n\n const dustUsd = calculateDustUsd(quote, request, targetFiatRate);\n const dust = getFiatValueFromUsd(dustUsd, usdToFiatRate);\n\n const { sourceNetwork, gasLimits } = await calculateSourceNetworkCost(\n quote,\n messenger,\n request,\n );\n\n const targetNetwork = getFiatValueFromUsd(new BigNumber(0), usdToFiatRate);\n\n const inputAmountRaw = quote.inputAmount ?? '0';\n const outputAmountRaw = new BigNumber(\n quote.expectedOutputAmount ??\n quote.minOutputAmount ??\n request.targetAmountMinimum ??\n '0',\n ).toString(10);\n\n const sourceAmount = getAmountFromTokenAmount({\n amountRaw: inputAmountRaw,\n decimals: quote.inputToken.decimals,\n fiatRate: sourceFiatRate,\n });\n\n const providerUsd = calculateProviderUsd(\n quote,\n inputAmountRaw,\n sourceFiatRate,\n targetFiatRate,\n quote.expectedOutputAmount,\n );\n const provider = getFiatValueFromUsd(providerUsd, usdToFiatRate);\n const metaMaskFee = getFiatValueFromUsd(\n new BigNumber(quote.fees?.app?.amountUsd ?? '0').abs(),\n usdToFiatRate,\n );\n\n const targetAmount = getAmountFromTokenAmount({\n amountRaw: outputAmountRaw,\n decimals: quote.outputToken.decimals,\n fiatRate: targetFiatRate,\n });\n\n const metamask = {\n gasLimits,\n };\n\n return {\n dust,\n estimatedDuration: quote.expectedFillTime ?? 0,\n fees: {\n metaMask: metaMaskFee,\n provider,\n sourceNetwork,\n targetNetwork,\n },\n original: {\n ...original,\n metamask,\n },\n request,\n sourceAmount,\n targetAmount,\n strategy: TransactionPayStrategy.Across,\n } as TransactionPayQuote<AcrossQuote>;\n}\n\nfunction getFiatRates(\n messenger: TransactionPayControllerMessenger,\n quote: AcrossSwapApprovalResponse,\n): {\n sourceFiatRate: FiatRates;\n targetFiatRate: FiatRates;\n usdToFiatRate: BigNumber;\n} {\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n quote.inputToken.address,\n toHex(quote.inputToken.chainId),\n );\n\n if (!sourceFiatRate) {\n throw new Error('Source token fiat rate not found');\n }\n\n const targetFiatRate =\n getTokenFiatRate(\n messenger,\n quote.outputToken.address,\n toHex(quote.outputToken.chainId),\n ) ?? sourceFiatRate;\n\n const usdToFiatRate = new BigNumber(sourceFiatRate.fiatRate).dividedBy(\n sourceFiatRate.usdRate,\n );\n\n return { sourceFiatRate, targetFiatRate, usdToFiatRate };\n}\n\nfunction calculateDustUsd(\n quote: AcrossSwapApprovalResponse,\n request: QuoteRequest,\n targetFiatRate: FiatRates,\n): BigNumber {\n const expectedOutputRaw = quote.expectedOutputAmount;\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n const minimumOutput = new BigNumber(\n quote.minOutputAmount ?? request.targetAmountMinimum ?? '0',\n );\n\n const dustRaw = expectedOutput.minus(minimumOutput).isNegative()\n ? new BigNumber(0)\n : expectedOutput.minus(minimumOutput);\n const dustHuman = dustRaw.shiftedBy(-quote.outputToken.decimals);\n\n return dustHuman.multipliedBy(targetFiatRate.usdRate);\n}\n\nfunction calculateProviderUsd(\n quote: AcrossSwapApprovalResponse,\n inputAmountRaw: string,\n sourceFiatRate: FiatRates,\n targetFiatRate: FiatRates,\n expectedOutputRaw?: string,\n): BigNumber {\n const totalFeeUsd = quote.fees?.total?.amountUsd;\n\n if (totalFeeUsd !== undefined) {\n return new BigNumber(totalFeeUsd).abs();\n }\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n\n if (expectedOutput.lte(0)) {\n return new BigNumber(0);\n }\n\n const inputAmountUsd = new BigNumber(inputAmountRaw)\n .shiftedBy(-quote.inputToken.decimals)\n .multipliedBy(sourceFiatRate.usdRate);\n const expectedOutputUsd = expectedOutput\n .shiftedBy(-quote.outputToken.decimals)\n .multipliedBy(targetFiatRate.usdRate);\n const providerFeeUsd = inputAmountUsd.minus(expectedOutputUsd);\n\n return providerFeeUsd.isNegative() ? new BigNumber(0) : providerFeeUsd;\n}\n\nfunction getAmountFromTokenAmount({\n amountRaw,\n decimals,\n fiatRate,\n}: {\n amountRaw: string;\n decimals: number;\n fiatRate: FiatRates;\n}): Amount {\n const rawValue = new BigNumber(amountRaw);\n const raw = rawValue.toString(10);\n\n const humanValue = rawValue.shiftedBy(-decimals);\n const human = humanValue.toString(10);\n\n const usd = humanValue.multipliedBy(fiatRate.usdRate).toString(10);\n const fiat = humanValue.multipliedBy(fiatRate.fiatRate).toString(10);\n\n return {\n fiat,\n human,\n raw,\n usd,\n };\n}\n\nasync function calculateSourceNetworkCost(\n quote: AcrossSwapApprovalResponse,\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n): Promise<{\n sourceNetwork: TransactionPayQuote<AcrossQuote>['fees']['sourceNetwork'];\n gasLimits: AcrossGasLimits;\n}> {\n const acrossFallbackGas =\n getPayStrategiesConfig(messenger).across.fallbackGas;\n const { from } = request;\n const approvalTxns = quote.approvalTxns ?? [];\n const { swapTx } = quote;\n const swapChainId = toHex(swapTx.chainId);\n\n const approvalGasResults = await Promise.all(\n approvalTxns.map(async (approval) => {\n const chainId = toHex(approval.chainId);\n const gas = await estimateGasLimit({\n chainId,\n data: approval.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: approval.to,\n value: approval.value ?? '0x0',\n });\n\n if (gas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: gas.error,\n transactionType: 'approval',\n });\n }\n\n return { chainId, gas };\n }),\n );\n\n const swapGasFromQuote = parseAcrossSwapGasLimit(swapTx.gas);\n const swapGas =\n swapGasFromQuote === undefined\n ? await estimateGasLimit({\n chainId: swapChainId,\n data: swapTx.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: swapTx.to,\n value: swapTx.value ?? '0x0',\n })\n : {\n estimate: swapGasFromQuote,\n max: swapGasFromQuote,\n usedFallback: false,\n };\n\n if (swapGasFromQuote !== undefined) {\n log('Using Across-provided swap gas limit', {\n gas: swapGasFromQuote,\n transactionType: 'swap',\n });\n } else if (swapGas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: swapGas.error,\n transactionType: 'swap',\n });\n }\n\n const estimate = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.estimate,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.estimate,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n const max = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.max,\n isMax: true,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.max,\n isMax: true,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n return {\n sourceNetwork: {\n estimate,\n max,\n },\n gasLimits: {\n approval: approvalGasResults.map(({ gas }) => ({\n estimate: gas.estimate,\n max: gas.max,\n })),\n swap: {\n estimate: swapGas.estimate,\n max: swapGas.max,\n },\n },\n };\n}\n\nfunction parseAcrossSwapGasLimit(gas?: string): number | undefined {\n if (!gas) {\n return undefined;\n }\n\n const parsedGas = gas.startsWith('0x')\n ? new BigNumber(gas.slice(2), 16)\n : new BigNumber(gas);\n\n if (\n !parsedGas.isFinite() ||\n parsedGas.isNaN() ||\n !parsedGas.isInteger() ||\n parsedGas.lte(0)\n ) {\n return undefined;\n }\n\n return parsedGas.toNumber();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"across-quotes.cjs","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,iEAAoE;AACpE,6EAAmE;AAGn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IAEvB,IACE,CAAC,SAAS,CAAC,QAAQ,EAAE;QACrB,SAAS,CAAC,KAAK,EAAE;QACjB,CAAC,SAAS,CAAC,SAAS,EAAE;QACtB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAChB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { successfulFetch, toHex } from '@metamask/controller-utils';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n AcrossAction,\n AcrossActionRequestBody,\n AcrossGasLimits,\n AcrossQuote,\n AcrossSwapApprovalResponse,\n} from './types';\nimport { TransactionPayStrategy } from '../../constants';\nimport { projectLogger } from '../../logger';\nimport type {\n Amount,\n FiatRates,\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\nimport { getFiatValueFromUsd, sumAmounts } from '../../utils/amounts';\nimport { getPayStrategiesConfig, getSlippage } from '../../utils/feature-flags';\nimport { calculateGasCost, estimateGasLimit } from '../../utils/gas';\nimport { getTokenFiatRate } from '../../utils/token';\nimport { TOKEN_TRANSFER_FOUR_BYTE } from '../relay/constants';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\n\nconst TOKEN_TRANSFER_INTERFACE = new Interface([\n 'function transfer(address to, uint256 value)',\n]);\n\nconst UNSUPPORTED_AUTHORIZATION_LIST_ERROR =\n 'Across does not support type-4/EIP-7702 authorization lists yet';\nconst UNSUPPORTED_DESTINATION_ERROR =\n 'Across only supports transfer-style destination flows at the moment';\n\ntype AcrossQuoteWithoutMetaMask = Omit<AcrossQuote, 'metamask'>;\n\ntype AcrossDestination = {\n actions: AcrossAction[];\n recipient: Hex;\n};\n\n/**\n * Fetch Across quotes.\n *\n * @param request - Request object.\n * @returns Array of quotes.\n */\nexport async function getAcrossQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>[]> {\n const { requests } = request;\n\n log('Fetching quotes', requests);\n\n try {\n const normalizedRequests = requests.filter(\n (singleRequest) =>\n singleRequest.isMaxAmount === true ||\n (singleRequest.targetAmountMinimum !== undefined &&\n singleRequest.targetAmountMinimum !== '0'),\n );\n\n if (normalizedRequests.length === 0) {\n return [];\n }\n\n if (request.transaction.txParams?.authorizationList?.length) {\n throw new Error(UNSUPPORTED_AUTHORIZATION_LIST_ERROR);\n }\n\n return await Promise.all(\n normalizedRequests.map((singleRequest) =>\n getSingleQuote(singleRequest, request),\n ),\n );\n } catch (error) {\n log('Error fetching quotes', { error });\n throw new Error(`Failed to fetch Across quotes: ${String(error)}`);\n }\n}\n\nasync function getSingleQuote(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger, transaction } = fullRequest;\n const {\n from,\n isMaxAmount,\n sourceChainId,\n sourceTokenAddress,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = request;\n\n const config = getPayStrategiesConfig(messenger);\n const slippageDecimal = getSlippage(\n messenger,\n sourceChainId,\n sourceTokenAddress,\n );\n\n const amount = isMaxAmount ? sourceTokenAmount : targetAmountMinimum;\n const tradeType = isMaxAmount ? 'exactInput' : 'exactOutput';\n const destination = getAcrossDestination(transaction, request);\n const quote = await requestAcrossApproval({\n actions: destination.actions,\n amount,\n apiBase: config.across.apiBase,\n depositor: from,\n destinationChainId: targetChainId,\n inputToken: sourceTokenAddress,\n originChainId: sourceChainId,\n outputToken: targetTokenAddress,\n recipient: destination.recipient,\n slippage: slippageDecimal,\n tradeType,\n });\n\n const originalQuote: AcrossQuoteWithoutMetaMask = {\n quote,\n request: {\n amount,\n tradeType,\n },\n };\n\n return await normalizeQuote(originalQuote, request, fullRequest);\n}\n\ntype AcrossApprovalRequest = {\n actions: AcrossAction[];\n amount: string;\n apiBase: string;\n depositor: Hex;\n destinationChainId: Hex;\n inputToken: Hex;\n originChainId: Hex;\n outputToken: Hex;\n recipient: Hex;\n slippage?: number;\n tradeType: 'exactInput' | 'exactOutput';\n};\n\nasync function requestAcrossApproval(\n request: AcrossApprovalRequest,\n): Promise<AcrossSwapApprovalResponse> {\n const {\n actions,\n amount,\n apiBase,\n depositor,\n destinationChainId,\n inputToken,\n originChainId,\n outputToken,\n recipient,\n slippage,\n tradeType,\n } = request;\n\n const params = new URLSearchParams();\n params.set('tradeType', tradeType);\n params.set('amount', amount);\n params.set('inputToken', inputToken);\n params.set('outputToken', outputToken);\n params.set('originChainId', String(parseInt(originChainId, 16)));\n params.set('destinationChainId', String(parseInt(destinationChainId, 16)));\n params.set('depositor', depositor);\n params.set('recipient', recipient);\n\n if (slippage !== undefined) {\n params.set('slippage', String(slippage));\n }\n\n const body: AcrossActionRequestBody = { actions };\n const url = `${apiBase}/swap/approval?${params.toString()}`;\n const options: RequestInit = {\n body: JSON.stringify(body),\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n };\n const response = await successfulFetch(url, options);\n\n return (await response.json()) as AcrossSwapApprovalResponse;\n}\n\nfunction getAcrossDestination(\n transaction: TransactionMeta,\n request: QuoteRequest,\n): AcrossDestination {\n const { txParams } = transaction;\n const { from } = request;\n const transferData = getTransferData(transaction);\n\n if (transferData) {\n const transferRecipient = getTransferRecipient(transferData);\n\n if (transaction.type === TransactionType.predictDeposit) {\n return {\n actions: [buildAcrossTransferAction(transferRecipient, request)],\n recipient: from,\n };\n }\n\n return {\n actions: [],\n recipient: transferRecipient,\n };\n }\n\n const data = txParams?.data as Hex | undefined;\n const hasNoData = data === undefined || data === '0x';\n const nestedCalldata = getNestedCalldata(transaction);\n\n if (hasNoData && nestedCalldata.length === 0) {\n return {\n actions: [],\n recipient: from,\n };\n }\n\n throw new Error(UNSUPPORTED_DESTINATION_ERROR);\n}\n\nfunction buildAcrossTransferAction(\n transferRecipient: Hex,\n request: QuoteRequest,\n): AcrossAction {\n return {\n args: [\n {\n populateDynamically: false,\n value: transferRecipient,\n },\n {\n balanceSourceToken: request.targetTokenAddress,\n populateDynamically: true,\n value: '0',\n },\n ],\n functionSignature: 'function transfer(address to, uint256 value)',\n isNativeTransfer: false,\n target: request.targetTokenAddress,\n value: '0',\n };\n}\n\nfunction getTransferData(transaction: TransactionMeta): Hex | undefined {\n const { nestedTransactions, txParams } = transaction;\n\n const nestedTransferData = nestedTransactions?.find(\n (nestedTx: { data?: Hex }) =>\n nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE),\n )?.data;\n\n const data = txParams?.data as Hex | undefined;\n const tokenTransferData = data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE)\n ? data\n : undefined;\n\n return nestedTransferData ?? tokenTransferData;\n}\n\nfunction getNestedCalldata(transaction: TransactionMeta): Hex[] {\n return (transaction.nestedTransactions ?? [])\n .map((nestedTx: { data?: Hex }) => nestedTx.data)\n .filter(\n (data: Hex | undefined): data is Hex =>\n data !== undefined && data !== '0x',\n );\n}\n\nfunction getTransferRecipient(data: Hex): Hex {\n return TOKEN_TRANSFER_INTERFACE.decodeFunctionData(\n 'transfer',\n data,\n ).to.toLowerCase() as Hex;\n}\n\nasync function normalizeQuote(\n original: AcrossQuoteWithoutMetaMask,\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger } = fullRequest;\n const { quote } = original;\n\n const { usdToFiatRate, sourceFiatRate, targetFiatRate } = getFiatRates(\n messenger,\n quote,\n );\n\n const dustUsd = calculateDustUsd(quote, request, targetFiatRate);\n const dust = getFiatValueFromUsd(dustUsd, usdToFiatRate);\n\n const { sourceNetwork, gasLimits } = await calculateSourceNetworkCost(\n quote,\n messenger,\n request,\n );\n\n const targetNetwork = getFiatValueFromUsd(new BigNumber(0), usdToFiatRate);\n\n const inputAmountRaw = quote.inputAmount ?? '0';\n const outputAmountRaw = new BigNumber(\n quote.expectedOutputAmount ??\n quote.minOutputAmount ??\n request.targetAmountMinimum ??\n '0',\n ).toString(10);\n\n const sourceAmount = getAmountFromTokenAmount({\n amountRaw: inputAmountRaw,\n decimals: quote.inputToken.decimals,\n fiatRate: sourceFiatRate,\n });\n\n const providerUsd = calculateProviderUsd(\n quote,\n inputAmountRaw,\n sourceFiatRate,\n targetFiatRate,\n quote.expectedOutputAmount,\n );\n const provider = getFiatValueFromUsd(providerUsd, usdToFiatRate);\n const metaMaskFee = getFiatValueFromUsd(\n new BigNumber(quote.fees?.app?.amountUsd ?? '0').abs(),\n usdToFiatRate,\n );\n\n const targetAmount = getAmountFromTokenAmount({\n amountRaw: outputAmountRaw,\n decimals: quote.outputToken.decimals,\n fiatRate: targetFiatRate,\n });\n\n const metamask = {\n gasLimits,\n };\n\n return {\n dust,\n estimatedDuration: quote.expectedFillTime ?? 0,\n fees: {\n metaMask: metaMaskFee,\n provider,\n sourceNetwork,\n targetNetwork,\n },\n original: {\n ...original,\n metamask,\n },\n request,\n sourceAmount,\n targetAmount,\n strategy: TransactionPayStrategy.Across,\n } as TransactionPayQuote<AcrossQuote>;\n}\n\nfunction getFiatRates(\n messenger: TransactionPayControllerMessenger,\n quote: AcrossSwapApprovalResponse,\n): {\n sourceFiatRate: FiatRates;\n targetFiatRate: FiatRates;\n usdToFiatRate: BigNumber;\n} {\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n quote.inputToken.address,\n toHex(quote.inputToken.chainId),\n );\n\n if (!sourceFiatRate) {\n throw new Error('Source token fiat rate not found');\n }\n\n const targetFiatRate =\n getTokenFiatRate(\n messenger,\n quote.outputToken.address,\n toHex(quote.outputToken.chainId),\n ) ?? sourceFiatRate;\n\n const usdToFiatRate = new BigNumber(sourceFiatRate.fiatRate).dividedBy(\n sourceFiatRate.usdRate,\n );\n\n return { sourceFiatRate, targetFiatRate, usdToFiatRate };\n}\n\nfunction calculateDustUsd(\n quote: AcrossSwapApprovalResponse,\n request: QuoteRequest,\n targetFiatRate: FiatRates,\n): BigNumber {\n const expectedOutputRaw = quote.expectedOutputAmount;\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n const minimumOutput = new BigNumber(\n quote.minOutputAmount ?? request.targetAmountMinimum ?? '0',\n );\n\n const dustRaw = expectedOutput.minus(minimumOutput).isNegative()\n ? new BigNumber(0)\n : expectedOutput.minus(minimumOutput);\n const dustHuman = dustRaw.shiftedBy(-quote.outputToken.decimals);\n\n return dustHuman.multipliedBy(targetFiatRate.usdRate);\n}\n\nfunction calculateProviderUsd(\n quote: AcrossSwapApprovalResponse,\n inputAmountRaw: string,\n sourceFiatRate: FiatRates,\n targetFiatRate: FiatRates,\n expectedOutputRaw?: string,\n): BigNumber {\n const totalFeeUsd = quote.fees?.total?.amountUsd;\n\n if (totalFeeUsd !== undefined) {\n return new BigNumber(totalFeeUsd).abs();\n }\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n\n if (expectedOutput.lte(0)) {\n return new BigNumber(0);\n }\n\n const inputAmountUsd = new BigNumber(inputAmountRaw)\n .shiftedBy(-quote.inputToken.decimals)\n .multipliedBy(sourceFiatRate.usdRate);\n const expectedOutputUsd = expectedOutput\n .shiftedBy(-quote.outputToken.decimals)\n .multipliedBy(targetFiatRate.usdRate);\n const providerFeeUsd = inputAmountUsd.minus(expectedOutputUsd);\n\n return providerFeeUsd.isNegative() ? new BigNumber(0) : providerFeeUsd;\n}\n\nfunction getAmountFromTokenAmount({\n amountRaw,\n decimals,\n fiatRate,\n}: {\n amountRaw: string;\n decimals: number;\n fiatRate: FiatRates;\n}): Amount {\n const rawValue = new BigNumber(amountRaw);\n const raw = rawValue.toString(10);\n\n const humanValue = rawValue.shiftedBy(-decimals);\n const human = humanValue.toString(10);\n\n const usd = humanValue.multipliedBy(fiatRate.usdRate).toString(10);\n const fiat = humanValue.multipliedBy(fiatRate.fiatRate).toString(10);\n\n return {\n fiat,\n human,\n raw,\n usd,\n };\n}\n\nasync function calculateSourceNetworkCost(\n quote: AcrossSwapApprovalResponse,\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n): Promise<{\n sourceNetwork: TransactionPayQuote<AcrossQuote>['fees']['sourceNetwork'];\n gasLimits: AcrossGasLimits;\n}> {\n const acrossFallbackGas =\n getPayStrategiesConfig(messenger).across.fallbackGas;\n const { from } = request;\n const approvalTxns = quote.approvalTxns ?? [];\n const { swapTx } = quote;\n const swapChainId = toHex(swapTx.chainId);\n\n const approvalGasResults = await Promise.all(\n approvalTxns.map(async (approval) => {\n const chainId = toHex(approval.chainId);\n const gas = await estimateGasLimit({\n chainId,\n data: approval.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: approval.to,\n value: approval.value ?? '0x0',\n });\n\n if (gas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: gas.error,\n transactionType: 'approval',\n });\n }\n\n return { chainId, gas };\n }),\n );\n\n const swapGasFromQuote = parseAcrossSwapGasLimit(swapTx.gas);\n const swapGas =\n swapGasFromQuote === undefined\n ? await estimateGasLimit({\n chainId: swapChainId,\n data: swapTx.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: swapTx.to,\n value: swapTx.value ?? '0x0',\n })\n : {\n estimate: swapGasFromQuote,\n max: swapGasFromQuote,\n usedFallback: false,\n };\n\n if (swapGasFromQuote !== undefined) {\n log('Using Across-provided swap gas limit', {\n gas: swapGasFromQuote,\n transactionType: 'swap',\n });\n } else if (swapGas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: swapGas.error,\n transactionType: 'swap',\n });\n }\n\n const estimate = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.estimate,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.estimate,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n const max = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.max,\n isMax: true,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.max,\n isMax: true,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n return {\n sourceNetwork: {\n estimate,\n max,\n },\n gasLimits: {\n approval: approvalGasResults.map(({ gas }) => ({\n estimate: gas.estimate,\n max: gas.max,\n })),\n swap: {\n estimate: swapGas.estimate,\n max: swapGas.max,\n },\n },\n };\n}\n\nfunction parseAcrossSwapGasLimit(gas?: string): number | undefined {\n if (!gas) {\n return undefined;\n }\n\n const parsedGas = gas.startsWith('0x')\n ? new BigNumber(gas.slice(2), 16)\n : new BigNumber(gas);\n\n if (\n !parsedGas.isFinite() ||\n parsedGas.isNaN() ||\n !parsedGas.isInteger() ||\n parsedGas.lte(0)\n ) {\n return undefined;\n }\n\n return parsedGas.toNumber();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"across-quotes.d.cts","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"across-quotes.d.cts","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAIV,WAAW,EAEZ,oBAAgB;AAGjB,OAAO,KAAK,EAGV,2BAA2B,EAG3B,mBAAmB,EACpB,wBAAoB;AAyBrB;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC,CA8B7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"across-quotes.d.mts","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"across-quotes.d.mts","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAIV,WAAW,EAEZ,oBAAgB;AAGjB,OAAO,KAAK,EAGV,2BAA2B,EAG3B,mBAAmB,EACpB,wBAAoB;AAyBrB;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC,CA8B7C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Interface } from "@ethersproject/abi";
|
|
2
2
|
import { successfulFetch, toHex } from "@metamask/controller-utils";
|
|
3
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
|
3
4
|
import { createModuleLogger } from "@metamask/utils";
|
|
4
5
|
import { BigNumber } from "bignumber.js";
|
|
5
6
|
import { TransactionPayStrategy } from "../../constants.mjs";
|
|
@@ -11,7 +12,7 @@ import { getTokenFiatRate } from "../../utils/token.mjs";
|
|
|
11
12
|
import { TOKEN_TRANSFER_FOUR_BYTE } from "../relay/constants.mjs";
|
|
12
13
|
const log = createModuleLogger(projectLogger, 'across-strategy');
|
|
13
14
|
const TOKEN_TRANSFER_INTERFACE = new Interface([
|
|
14
|
-
'function transfer(address to, uint256
|
|
15
|
+
'function transfer(address to, uint256 value)',
|
|
15
16
|
]);
|
|
16
17
|
const UNSUPPORTED_AUTHORIZATION_LIST_ERROR = 'Across does not support type-4/EIP-7702 authorization lists yet';
|
|
17
18
|
const UNSUPPORTED_DESTINATION_ERROR = 'Across only supports transfer-style destination flows at the moment';
|
|
@@ -48,8 +49,9 @@ async function getSingleQuote(request, fullRequest) {
|
|
|
48
49
|
const slippageDecimal = getSlippage(messenger, sourceChainId, sourceTokenAddress);
|
|
49
50
|
const amount = isMaxAmount ? sourceTokenAmount : targetAmountMinimum;
|
|
50
51
|
const tradeType = isMaxAmount ? 'exactInput' : 'exactOutput';
|
|
51
|
-
const
|
|
52
|
+
const destination = getAcrossDestination(transaction, request);
|
|
52
53
|
const quote = await requestAcrossApproval({
|
|
54
|
+
actions: destination.actions,
|
|
53
55
|
amount,
|
|
54
56
|
apiBase: config.across.apiBase,
|
|
55
57
|
depositor: from,
|
|
@@ -57,7 +59,7 @@ async function getSingleQuote(request, fullRequest) {
|
|
|
57
59
|
inputToken: sourceTokenAddress,
|
|
58
60
|
originChainId: sourceChainId,
|
|
59
61
|
outputToken: targetTokenAddress,
|
|
60
|
-
recipient,
|
|
62
|
+
recipient: destination.recipient,
|
|
61
63
|
slippage: slippageDecimal,
|
|
62
64
|
tradeType,
|
|
63
65
|
});
|
|
@@ -71,7 +73,7 @@ async function getSingleQuote(request, fullRequest) {
|
|
|
71
73
|
return await normalizeQuote(originalQuote, request, fullRequest);
|
|
72
74
|
}
|
|
73
75
|
async function requestAcrossApproval(request) {
|
|
74
|
-
const { amount, apiBase, depositor, destinationChainId, inputToken, originChainId, outputToken, recipient, slippage, tradeType, } = request;
|
|
76
|
+
const { actions, amount, apiBase, depositor, destinationChainId, inputToken, originChainId, outputToken, recipient, slippage, tradeType, } = request;
|
|
75
77
|
const params = new URLSearchParams();
|
|
76
78
|
params.set('tradeType', tradeType);
|
|
77
79
|
params.set('amount', amount);
|
|
@@ -84,7 +86,7 @@ async function requestAcrossApproval(request) {
|
|
|
84
86
|
if (slippage !== undefined) {
|
|
85
87
|
params.set('slippage', String(slippage));
|
|
86
88
|
}
|
|
87
|
-
const body = { actions
|
|
89
|
+
const body = { actions };
|
|
88
90
|
const url = `${apiBase}/swap/approval?${params.toString()}`;
|
|
89
91
|
const options = {
|
|
90
92
|
body: JSON.stringify(body),
|
|
@@ -97,21 +99,53 @@ async function requestAcrossApproval(request) {
|
|
|
97
99
|
const response = await successfulFetch(url, options);
|
|
98
100
|
return (await response.json());
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function getAcrossDestination(transaction, request) {
|
|
101
103
|
const { txParams } = transaction;
|
|
102
104
|
const { from } = request;
|
|
103
105
|
const transferData = getTransferData(transaction);
|
|
104
106
|
if (transferData) {
|
|
105
|
-
|
|
107
|
+
const transferRecipient = getTransferRecipient(transferData);
|
|
108
|
+
if (transaction.type === TransactionType.predictDeposit) {
|
|
109
|
+
return {
|
|
110
|
+
actions: [buildAcrossTransferAction(transferRecipient, request)],
|
|
111
|
+
recipient: from,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
actions: [],
|
|
116
|
+
recipient: transferRecipient,
|
|
117
|
+
};
|
|
106
118
|
}
|
|
107
119
|
const data = txParams?.data;
|
|
108
120
|
const hasNoData = data === undefined || data === '0x';
|
|
109
121
|
const nestedCalldata = getNestedCalldata(transaction);
|
|
110
122
|
if (hasNoData && nestedCalldata.length === 0) {
|
|
111
|
-
return
|
|
123
|
+
return {
|
|
124
|
+
actions: [],
|
|
125
|
+
recipient: from,
|
|
126
|
+
};
|
|
112
127
|
}
|
|
113
128
|
throw new Error(UNSUPPORTED_DESTINATION_ERROR);
|
|
114
129
|
}
|
|
130
|
+
function buildAcrossTransferAction(transferRecipient, request) {
|
|
131
|
+
return {
|
|
132
|
+
args: [
|
|
133
|
+
{
|
|
134
|
+
populateDynamically: false,
|
|
135
|
+
value: transferRecipient,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
balanceSourceToken: request.targetTokenAddress,
|
|
139
|
+
populateDynamically: true,
|
|
140
|
+
value: '0',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
functionSignature: 'function transfer(address to, uint256 value)',
|
|
144
|
+
isNativeTransfer: false,
|
|
145
|
+
target: request.targetTokenAddress,
|
|
146
|
+
value: '0',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
115
149
|
function getTransferData(transaction) {
|
|
116
150
|
const { nestedTransactions, txParams } = transaction;
|
|
117
151
|
const nestedTransferData = nestedTransactions?.find((nestedTx) => nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE))?.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"across-quotes.mjs","sourceRoot":"","sources":["../../../src/strategy/across/across-quotes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,2BAA2B;AAC/C,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,mCAAmC;AAGpE,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAQzC,OAAO,EAAE,sBAAsB,EAAE,4BAAwB;AACzD,OAAO,EAAE,aAAa,EAAE,yBAAqB;AAS7C,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,gCAA4B;AACtE,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,sCAAkC;AAChF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAAwB;AACrE,OAAO,EAAE,gBAAgB,EAAE,8BAA0B;AACrD,OAAO,EAAE,wBAAwB,EAAE,+BAA2B;AAE9D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;AAEjE,MAAM,wBAAwB,GAAG,IAAI,SAAS,CAAC;IAC7C,+CAA+C;CAChD,CAAC,CAAC;AAEH,MAAM,oCAAoC,GACxC,iEAAiE,CAAC;AACpE,MAAM,6BAA6B,GACjC,qEAAqE,CAAC;AAIxE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAoC;IAEpC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IAEjC,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM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AAgB,CAAC;YACf,OAAO,EAAE,WAAW;YACpB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;YACjD,SAAS;SACV,CAAC;KACH,CAAC,CAAC;IAEH,OAAO;QACL,aAAa,EAAE;YACb,QAAQ;YACR,GAAG;SACJ;QACD,SAAS,EAAE;YACT,QAAQ,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7C,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,GAAG,EAAE,GAAG,CAAC,GAAG;aACb,CAAC,CAAC;YACH,IAAI,EAAE;gBACJ,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,GAAG,EAAE,OAAO,CAAC,GAAG;aACjB;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,GAAY;IAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QACpC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACjC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;IAEvB,IACE,CAAC,SAAS,CAAC,QAAQ,EAAE;QACrB,SAAS,CAAC,KAAK,EAAE;QACjB,CAAC,SAAS,CAAC,SAAS,EAAE;QACtB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAChB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { successfulFetch, toHex } from '@metamask/controller-utils';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n AcrossActionRequestBody,\n AcrossGasLimits,\n AcrossQuote,\n AcrossSwapApprovalResponse,\n} from './types';\nimport { TransactionPayStrategy } from '../../constants';\nimport { projectLogger } from '../../logger';\nimport type {\n Amount,\n FiatRates,\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\nimport { getFiatValueFromUsd, sumAmounts } from '../../utils/amounts';\nimport { getPayStrategiesConfig, getSlippage } from '../../utils/feature-flags';\nimport { calculateGasCost, estimateGasLimit } from '../../utils/gas';\nimport { getTokenFiatRate } from '../../utils/token';\nimport { TOKEN_TRANSFER_FOUR_BYTE } from '../relay/constants';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\n\nconst TOKEN_TRANSFER_INTERFACE = new Interface([\n 'function transfer(address to, uint256 amount)',\n]);\n\nconst UNSUPPORTED_AUTHORIZATION_LIST_ERROR =\n 'Across does not support type-4/EIP-7702 authorization lists yet';\nconst UNSUPPORTED_DESTINATION_ERROR =\n 'Across only supports transfer-style destination flows at the moment';\n\ntype AcrossQuoteWithoutMetaMask = Omit<AcrossQuote, 'metamask'>;\n\n/**\n * Fetch Across quotes.\n *\n * @param request - Request object.\n * @returns Array of quotes.\n */\nexport async function getAcrossQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>[]> {\n const { requests } = request;\n\n log('Fetching quotes', requests);\n\n try {\n const normalizedRequests = requests.filter(\n (singleRequest) =>\n singleRequest.isMaxAmount === true ||\n (singleRequest.targetAmountMinimum !== undefined &&\n singleRequest.targetAmountMinimum !== '0'),\n );\n\n if (normalizedRequests.length === 0) {\n return [];\n }\n\n if (request.transaction.txParams?.authorizationList?.length) {\n throw new Error(UNSUPPORTED_AUTHORIZATION_LIST_ERROR);\n }\n\n return await Promise.all(\n normalizedRequests.map((singleRequest) =>\n getSingleQuote(singleRequest, request),\n ),\n );\n } catch (error) {\n log('Error fetching quotes', { error });\n throw new Error(`Failed to fetch Across quotes: ${String(error)}`);\n }\n}\n\nasync function getSingleQuote(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger, transaction } = fullRequest;\n const {\n from,\n isMaxAmount,\n sourceChainId,\n sourceTokenAddress,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = request;\n\n const config = getPayStrategiesConfig(messenger);\n const slippageDecimal = getSlippage(\n messenger,\n sourceChainId,\n sourceTokenAddress,\n );\n\n const amount = isMaxAmount ? sourceTokenAmount : targetAmountMinimum;\n const tradeType = isMaxAmount ? 'exactInput' : 'exactOutput';\n const recipient = getAcrossRecipient(transaction, request);\n const quote = await requestAcrossApproval({\n amount,\n apiBase: config.across.apiBase,\n depositor: from,\n destinationChainId: targetChainId,\n inputToken: sourceTokenAddress,\n originChainId: sourceChainId,\n outputToken: targetTokenAddress,\n recipient,\n slippage: slippageDecimal,\n tradeType,\n });\n\n const originalQuote: AcrossQuoteWithoutMetaMask = {\n quote,\n request: {\n amount,\n tradeType,\n },\n };\n\n return await normalizeQuote(originalQuote, request, fullRequest);\n}\n\ntype AcrossApprovalRequest = {\n amount: string;\n apiBase: string;\n depositor: Hex;\n destinationChainId: Hex;\n inputToken: Hex;\n originChainId: Hex;\n outputToken: Hex;\n recipient: Hex;\n slippage?: number;\n tradeType: 'exactInput' | 'exactOutput';\n};\n\nasync function requestAcrossApproval(\n request: AcrossApprovalRequest,\n): Promise<AcrossSwapApprovalResponse> {\n const {\n amount,\n apiBase,\n depositor,\n destinationChainId,\n inputToken,\n originChainId,\n outputToken,\n recipient,\n slippage,\n tradeType,\n } = request;\n\n const params = new URLSearchParams();\n params.set('tradeType', tradeType);\n params.set('amount', amount);\n params.set('inputToken', inputToken);\n params.set('outputToken', outputToken);\n params.set('originChainId', String(parseInt(originChainId, 16)));\n params.set('destinationChainId', String(parseInt(destinationChainId, 16)));\n params.set('depositor', depositor);\n params.set('recipient', recipient);\n\n if (slippage !== undefined) {\n params.set('slippage', String(slippage));\n }\n\n const body: AcrossActionRequestBody = { actions: [] };\n const url = `${apiBase}/swap/approval?${params.toString()}`;\n const options: RequestInit = {\n body: JSON.stringify(body),\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n };\n const response = await successfulFetch(url, options);\n\n return (await response.json()) as AcrossSwapApprovalResponse;\n}\n\nfunction getAcrossRecipient(\n transaction: TransactionMeta,\n request: QuoteRequest,\n): Hex {\n const { txParams } = transaction;\n const { from } = request;\n const transferData = getTransferData(transaction);\n\n if (transferData) {\n return getTransferRecipient(transferData);\n }\n\n const data = txParams?.data as Hex | undefined;\n const hasNoData = data === undefined || data === '0x';\n const nestedCalldata = getNestedCalldata(transaction);\n\n if (hasNoData && nestedCalldata.length === 0) {\n return from;\n }\n\n throw new Error(UNSUPPORTED_DESTINATION_ERROR);\n}\n\nfunction getTransferData(transaction: TransactionMeta): Hex | undefined {\n const { nestedTransactions, txParams } = transaction;\n\n const nestedTransferData = nestedTransactions?.find(\n (nestedTx: { data?: Hex }) =>\n nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE),\n )?.data;\n\n const data = txParams?.data as Hex | undefined;\n const tokenTransferData = data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE)\n ? data\n : undefined;\n\n return nestedTransferData ?? tokenTransferData;\n}\n\nfunction getNestedCalldata(transaction: TransactionMeta): Hex[] {\n return (transaction.nestedTransactions ?? [])\n .map((nestedTx: { data?: Hex }) => nestedTx.data)\n .filter(\n (data: Hex | undefined): data is Hex =>\n data !== undefined && data !== '0x',\n );\n}\n\nfunction getTransferRecipient(data: Hex): Hex {\n return TOKEN_TRANSFER_INTERFACE.decodeFunctionData(\n 'transfer',\n data,\n ).to.toLowerCase() as Hex;\n}\n\nasync function normalizeQuote(\n original: AcrossQuoteWithoutMetaMask,\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger } = fullRequest;\n const { quote } = original;\n\n const { usdToFiatRate, sourceFiatRate, targetFiatRate } = getFiatRates(\n messenger,\n quote,\n );\n\n const dustUsd = calculateDustUsd(quote, request, targetFiatRate);\n const dust = getFiatValueFromUsd(dustUsd, usdToFiatRate);\n\n const { sourceNetwork, gasLimits } = await calculateSourceNetworkCost(\n quote,\n messenger,\n request,\n );\n\n const targetNetwork = getFiatValueFromUsd(new BigNumber(0), usdToFiatRate);\n\n const inputAmountRaw = quote.inputAmount ?? '0';\n const outputAmountRaw = new BigNumber(\n quote.expectedOutputAmount ??\n quote.minOutputAmount ??\n request.targetAmountMinimum ??\n '0',\n ).toString(10);\n\n const sourceAmount = getAmountFromTokenAmount({\n amountRaw: inputAmountRaw,\n decimals: quote.inputToken.decimals,\n fiatRate: sourceFiatRate,\n });\n\n const providerUsd = calculateProviderUsd(\n quote,\n inputAmountRaw,\n sourceFiatRate,\n targetFiatRate,\n quote.expectedOutputAmount,\n );\n const provider = getFiatValueFromUsd(providerUsd, usdToFiatRate);\n const metaMaskFee = getFiatValueFromUsd(\n new BigNumber(quote.fees?.app?.amountUsd ?? '0').abs(),\n usdToFiatRate,\n );\n\n const targetAmount = getAmountFromTokenAmount({\n amountRaw: outputAmountRaw,\n decimals: quote.outputToken.decimals,\n fiatRate: targetFiatRate,\n });\n\n const metamask = {\n gasLimits,\n };\n\n return {\n dust,\n estimatedDuration: quote.expectedFillTime ?? 0,\n fees: {\n metaMask: metaMaskFee,\n provider,\n sourceNetwork,\n targetNetwork,\n },\n original: {\n ...original,\n metamask,\n },\n request,\n sourceAmount,\n targetAmount,\n strategy: TransactionPayStrategy.Across,\n } as TransactionPayQuote<AcrossQuote>;\n}\n\nfunction getFiatRates(\n messenger: TransactionPayControllerMessenger,\n quote: AcrossSwapApprovalResponse,\n): {\n sourceFiatRate: FiatRates;\n targetFiatRate: FiatRates;\n usdToFiatRate: BigNumber;\n} {\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n quote.inputToken.address,\n toHex(quote.inputToken.chainId),\n );\n\n if (!sourceFiatRate) {\n throw new Error('Source token fiat rate not found');\n }\n\n const targetFiatRate =\n getTokenFiatRate(\n messenger,\n quote.outputToken.address,\n toHex(quote.outputToken.chainId),\n ) ?? sourceFiatRate;\n\n const usdToFiatRate = new BigNumber(sourceFiatRate.fiatRate).dividedBy(\n sourceFiatRate.usdRate,\n );\n\n return { sourceFiatRate, targetFiatRate, usdToFiatRate };\n}\n\nfunction calculateDustUsd(\n quote: AcrossSwapApprovalResponse,\n request: QuoteRequest,\n targetFiatRate: FiatRates,\n): BigNumber {\n const expectedOutputRaw = quote.expectedOutputAmount;\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n const minimumOutput = new BigNumber(\n quote.minOutputAmount ?? request.targetAmountMinimum ?? '0',\n );\n\n const dustRaw = expectedOutput.minus(minimumOutput).isNegative()\n ? new BigNumber(0)\n : expectedOutput.minus(minimumOutput);\n const dustHuman = dustRaw.shiftedBy(-quote.outputToken.decimals);\n\n return dustHuman.multipliedBy(targetFiatRate.usdRate);\n}\n\nfunction calculateProviderUsd(\n quote: AcrossSwapApprovalResponse,\n inputAmountRaw: string,\n sourceFiatRate: FiatRates,\n targetFiatRate: FiatRates,\n expectedOutputRaw?: string,\n): BigNumber {\n const totalFeeUsd = quote.fees?.total?.amountUsd;\n\n if (totalFeeUsd !== undefined) {\n return new BigNumber(totalFeeUsd).abs();\n }\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n\n if (expectedOutput.lte(0)) {\n return new BigNumber(0);\n }\n\n const inputAmountUsd = new BigNumber(inputAmountRaw)\n .shiftedBy(-quote.inputToken.decimals)\n .multipliedBy(sourceFiatRate.usdRate);\n const expectedOutputUsd = expectedOutput\n .shiftedBy(-quote.outputToken.decimals)\n .multipliedBy(targetFiatRate.usdRate);\n const providerFeeUsd = inputAmountUsd.minus(expectedOutputUsd);\n\n return providerFeeUsd.isNegative() ? new BigNumber(0) : providerFeeUsd;\n}\n\nfunction getAmountFromTokenAmount({\n amountRaw,\n decimals,\n fiatRate,\n}: {\n amountRaw: string;\n decimals: number;\n fiatRate: FiatRates;\n}): Amount {\n const rawValue = new BigNumber(amountRaw);\n const raw = rawValue.toString(10);\n\n const humanValue = rawValue.shiftedBy(-decimals);\n const human = humanValue.toString(10);\n\n const usd = humanValue.multipliedBy(fiatRate.usdRate).toString(10);\n const fiat = humanValue.multipliedBy(fiatRate.fiatRate).toString(10);\n\n return {\n fiat,\n human,\n raw,\n usd,\n };\n}\n\nasync function calculateSourceNetworkCost(\n quote: AcrossSwapApprovalResponse,\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n): Promise<{\n sourceNetwork: TransactionPayQuote<AcrossQuote>['fees']['sourceNetwork'];\n gasLimits: AcrossGasLimits;\n}> {\n const acrossFallbackGas =\n getPayStrategiesConfig(messenger).across.fallbackGas;\n const { from } = request;\n const approvalTxns = quote.approvalTxns ?? [];\n const { swapTx } = quote;\n const swapChainId = toHex(swapTx.chainId);\n\n const approvalGasResults = await Promise.all(\n approvalTxns.map(async (approval) => {\n const chainId = toHex(approval.chainId);\n const gas = await estimateGasLimit({\n chainId,\n data: approval.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: approval.to,\n value: approval.value ?? '0x0',\n });\n\n if (gas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: gas.error,\n transactionType: 'approval',\n });\n }\n\n return { chainId, gas };\n }),\n );\n\n const swapGasFromQuote = parseAcrossSwapGasLimit(swapTx.gas);\n const swapGas =\n swapGasFromQuote === undefined\n ? await estimateGasLimit({\n chainId: swapChainId,\n data: swapTx.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: swapTx.to,\n value: swapTx.value ?? '0x0',\n })\n : {\n estimate: swapGasFromQuote,\n max: swapGasFromQuote,\n usedFallback: false,\n };\n\n if (swapGasFromQuote !== undefined) {\n log('Using Across-provided swap gas limit', {\n gas: swapGasFromQuote,\n transactionType: 'swap',\n });\n } else if (swapGas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: swapGas.error,\n transactionType: 'swap',\n });\n }\n\n const estimate = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.estimate,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.estimate,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n const max = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.max,\n isMax: true,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.max,\n isMax: true,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n return {\n sourceNetwork: {\n estimate,\n max,\n },\n gasLimits: {\n approval: approvalGasResults.map(({ gas }) => ({\n estimate: gas.estimate,\n max: gas.max,\n })),\n swap: {\n estimate: swapGas.estimate,\n max: swapGas.max,\n },\n },\n };\n}\n\nfunction parseAcrossSwapGasLimit(gas?: string): number | undefined {\n if (!gas) {\n return undefined;\n }\n\n const parsedGas = gas.startsWith('0x')\n ? new BigNumber(gas.slice(2), 16)\n : new BigNumber(gas);\n\n if (\n !parsedGas.isFinite() ||\n parsedGas.isNaN() ||\n !parsedGas.isInteger() ||\n parsedGas.lte(0)\n ) {\n return undefined;\n }\n\n return parsedGas.toNumber();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"across-quotes.mjs","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AC,GAAY;IAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QACpC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACjC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;IAEvB,IACE,CAAC,SAAS,CAAC,QAAQ,EAAE;QACrB,SAAS,CAAC,KAAK,EAAE;QACjB,CAAC,SAAS,CAAC,SAAS,EAAE;QACtB,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAChB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { successfulFetch, toHex } from '@metamask/controller-utils';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport type {\n AcrossAction,\n AcrossActionRequestBody,\n AcrossGasLimits,\n AcrossQuote,\n AcrossSwapApprovalResponse,\n} from './types';\nimport { TransactionPayStrategy } from '../../constants';\nimport { projectLogger } from '../../logger';\nimport type {\n Amount,\n FiatRates,\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\nimport { getFiatValueFromUsd, sumAmounts } from '../../utils/amounts';\nimport { getPayStrategiesConfig, getSlippage } from '../../utils/feature-flags';\nimport { calculateGasCost, estimateGasLimit } from '../../utils/gas';\nimport { getTokenFiatRate } from '../../utils/token';\nimport { TOKEN_TRANSFER_FOUR_BYTE } from '../relay/constants';\n\nconst log = createModuleLogger(projectLogger, 'across-strategy');\n\nconst TOKEN_TRANSFER_INTERFACE = new Interface([\n 'function transfer(address to, uint256 value)',\n]);\n\nconst UNSUPPORTED_AUTHORIZATION_LIST_ERROR =\n 'Across does not support type-4/EIP-7702 authorization lists yet';\nconst UNSUPPORTED_DESTINATION_ERROR =\n 'Across only supports transfer-style destination flows at the moment';\n\ntype AcrossQuoteWithoutMetaMask = Omit<AcrossQuote, 'metamask'>;\n\ntype AcrossDestination = {\n actions: AcrossAction[];\n recipient: Hex;\n};\n\n/**\n * Fetch Across quotes.\n *\n * @param request - Request object.\n * @returns Array of quotes.\n */\nexport async function getAcrossQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>[]> {\n const { requests } = request;\n\n log('Fetching quotes', requests);\n\n try {\n const normalizedRequests = requests.filter(\n (singleRequest) =>\n singleRequest.isMaxAmount === true ||\n (singleRequest.targetAmountMinimum !== undefined &&\n singleRequest.targetAmountMinimum !== '0'),\n );\n\n if (normalizedRequests.length === 0) {\n return [];\n }\n\n if (request.transaction.txParams?.authorizationList?.length) {\n throw new Error(UNSUPPORTED_AUTHORIZATION_LIST_ERROR);\n }\n\n return await Promise.all(\n normalizedRequests.map((singleRequest) =>\n getSingleQuote(singleRequest, request),\n ),\n );\n } catch (error) {\n log('Error fetching quotes', { error });\n throw new Error(`Failed to fetch Across quotes: ${String(error)}`);\n }\n}\n\nasync function getSingleQuote(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger, transaction } = fullRequest;\n const {\n from,\n isMaxAmount,\n sourceChainId,\n sourceTokenAddress,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = request;\n\n const config = getPayStrategiesConfig(messenger);\n const slippageDecimal = getSlippage(\n messenger,\n sourceChainId,\n sourceTokenAddress,\n );\n\n const amount = isMaxAmount ? sourceTokenAmount : targetAmountMinimum;\n const tradeType = isMaxAmount ? 'exactInput' : 'exactOutput';\n const destination = getAcrossDestination(transaction, request);\n const quote = await requestAcrossApproval({\n actions: destination.actions,\n amount,\n apiBase: config.across.apiBase,\n depositor: from,\n destinationChainId: targetChainId,\n inputToken: sourceTokenAddress,\n originChainId: sourceChainId,\n outputToken: targetTokenAddress,\n recipient: destination.recipient,\n slippage: slippageDecimal,\n tradeType,\n });\n\n const originalQuote: AcrossQuoteWithoutMetaMask = {\n quote,\n request: {\n amount,\n tradeType,\n },\n };\n\n return await normalizeQuote(originalQuote, request, fullRequest);\n}\n\ntype AcrossApprovalRequest = {\n actions: AcrossAction[];\n amount: string;\n apiBase: string;\n depositor: Hex;\n destinationChainId: Hex;\n inputToken: Hex;\n originChainId: Hex;\n outputToken: Hex;\n recipient: Hex;\n slippage?: number;\n tradeType: 'exactInput' | 'exactOutput';\n};\n\nasync function requestAcrossApproval(\n request: AcrossApprovalRequest,\n): Promise<AcrossSwapApprovalResponse> {\n const {\n actions,\n amount,\n apiBase,\n depositor,\n destinationChainId,\n inputToken,\n originChainId,\n outputToken,\n recipient,\n slippage,\n tradeType,\n } = request;\n\n const params = new URLSearchParams();\n params.set('tradeType', tradeType);\n params.set('amount', amount);\n params.set('inputToken', inputToken);\n params.set('outputToken', outputToken);\n params.set('originChainId', String(parseInt(originChainId, 16)));\n params.set('destinationChainId', String(parseInt(destinationChainId, 16)));\n params.set('depositor', depositor);\n params.set('recipient', recipient);\n\n if (slippage !== undefined) {\n params.set('slippage', String(slippage));\n }\n\n const body: AcrossActionRequestBody = { actions };\n const url = `${apiBase}/swap/approval?${params.toString()}`;\n const options: RequestInit = {\n body: JSON.stringify(body),\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n };\n const response = await successfulFetch(url, options);\n\n return (await response.json()) as AcrossSwapApprovalResponse;\n}\n\nfunction getAcrossDestination(\n transaction: TransactionMeta,\n request: QuoteRequest,\n): AcrossDestination {\n const { txParams } = transaction;\n const { from } = request;\n const transferData = getTransferData(transaction);\n\n if (transferData) {\n const transferRecipient = getTransferRecipient(transferData);\n\n if (transaction.type === TransactionType.predictDeposit) {\n return {\n actions: [buildAcrossTransferAction(transferRecipient, request)],\n recipient: from,\n };\n }\n\n return {\n actions: [],\n recipient: transferRecipient,\n };\n }\n\n const data = txParams?.data as Hex | undefined;\n const hasNoData = data === undefined || data === '0x';\n const nestedCalldata = getNestedCalldata(transaction);\n\n if (hasNoData && nestedCalldata.length === 0) {\n return {\n actions: [],\n recipient: from,\n };\n }\n\n throw new Error(UNSUPPORTED_DESTINATION_ERROR);\n}\n\nfunction buildAcrossTransferAction(\n transferRecipient: Hex,\n request: QuoteRequest,\n): AcrossAction {\n return {\n args: [\n {\n populateDynamically: false,\n value: transferRecipient,\n },\n {\n balanceSourceToken: request.targetTokenAddress,\n populateDynamically: true,\n value: '0',\n },\n ],\n functionSignature: 'function transfer(address to, uint256 value)',\n isNativeTransfer: false,\n target: request.targetTokenAddress,\n value: '0',\n };\n}\n\nfunction getTransferData(transaction: TransactionMeta): Hex | undefined {\n const { nestedTransactions, txParams } = transaction;\n\n const nestedTransferData = nestedTransactions?.find(\n (nestedTx: { data?: Hex }) =>\n nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE),\n )?.data;\n\n const data = txParams?.data as Hex | undefined;\n const tokenTransferData = data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE)\n ? data\n : undefined;\n\n return nestedTransferData ?? tokenTransferData;\n}\n\nfunction getNestedCalldata(transaction: TransactionMeta): Hex[] {\n return (transaction.nestedTransactions ?? [])\n .map((nestedTx: { data?: Hex }) => nestedTx.data)\n .filter(\n (data: Hex | undefined): data is Hex =>\n data !== undefined && data !== '0x',\n );\n}\n\nfunction getTransferRecipient(data: Hex): Hex {\n return TOKEN_TRANSFER_INTERFACE.decodeFunctionData(\n 'transfer',\n data,\n ).to.toLowerCase() as Hex;\n}\n\nasync function normalizeQuote(\n original: AcrossQuoteWithoutMetaMask,\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<AcrossQuote>> {\n const { messenger } = fullRequest;\n const { quote } = original;\n\n const { usdToFiatRate, sourceFiatRate, targetFiatRate } = getFiatRates(\n messenger,\n quote,\n );\n\n const dustUsd = calculateDustUsd(quote, request, targetFiatRate);\n const dust = getFiatValueFromUsd(dustUsd, usdToFiatRate);\n\n const { sourceNetwork, gasLimits } = await calculateSourceNetworkCost(\n quote,\n messenger,\n request,\n );\n\n const targetNetwork = getFiatValueFromUsd(new BigNumber(0), usdToFiatRate);\n\n const inputAmountRaw = quote.inputAmount ?? '0';\n const outputAmountRaw = new BigNumber(\n quote.expectedOutputAmount ??\n quote.minOutputAmount ??\n request.targetAmountMinimum ??\n '0',\n ).toString(10);\n\n const sourceAmount = getAmountFromTokenAmount({\n amountRaw: inputAmountRaw,\n decimals: quote.inputToken.decimals,\n fiatRate: sourceFiatRate,\n });\n\n const providerUsd = calculateProviderUsd(\n quote,\n inputAmountRaw,\n sourceFiatRate,\n targetFiatRate,\n quote.expectedOutputAmount,\n );\n const provider = getFiatValueFromUsd(providerUsd, usdToFiatRate);\n const metaMaskFee = getFiatValueFromUsd(\n new BigNumber(quote.fees?.app?.amountUsd ?? '0').abs(),\n usdToFiatRate,\n );\n\n const targetAmount = getAmountFromTokenAmount({\n amountRaw: outputAmountRaw,\n decimals: quote.outputToken.decimals,\n fiatRate: targetFiatRate,\n });\n\n const metamask = {\n gasLimits,\n };\n\n return {\n dust,\n estimatedDuration: quote.expectedFillTime ?? 0,\n fees: {\n metaMask: metaMaskFee,\n provider,\n sourceNetwork,\n targetNetwork,\n },\n original: {\n ...original,\n metamask,\n },\n request,\n sourceAmount,\n targetAmount,\n strategy: TransactionPayStrategy.Across,\n } as TransactionPayQuote<AcrossQuote>;\n}\n\nfunction getFiatRates(\n messenger: TransactionPayControllerMessenger,\n quote: AcrossSwapApprovalResponse,\n): {\n sourceFiatRate: FiatRates;\n targetFiatRate: FiatRates;\n usdToFiatRate: BigNumber;\n} {\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n quote.inputToken.address,\n toHex(quote.inputToken.chainId),\n );\n\n if (!sourceFiatRate) {\n throw new Error('Source token fiat rate not found');\n }\n\n const targetFiatRate =\n getTokenFiatRate(\n messenger,\n quote.outputToken.address,\n toHex(quote.outputToken.chainId),\n ) ?? sourceFiatRate;\n\n const usdToFiatRate = new BigNumber(sourceFiatRate.fiatRate).dividedBy(\n sourceFiatRate.usdRate,\n );\n\n return { sourceFiatRate, targetFiatRate, usdToFiatRate };\n}\n\nfunction calculateDustUsd(\n quote: AcrossSwapApprovalResponse,\n request: QuoteRequest,\n targetFiatRate: FiatRates,\n): BigNumber {\n const expectedOutputRaw = quote.expectedOutputAmount;\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n const minimumOutput = new BigNumber(\n quote.minOutputAmount ?? request.targetAmountMinimum ?? '0',\n );\n\n const dustRaw = expectedOutput.minus(minimumOutput).isNegative()\n ? new BigNumber(0)\n : expectedOutput.minus(minimumOutput);\n const dustHuman = dustRaw.shiftedBy(-quote.outputToken.decimals);\n\n return dustHuman.multipliedBy(targetFiatRate.usdRate);\n}\n\nfunction calculateProviderUsd(\n quote: AcrossSwapApprovalResponse,\n inputAmountRaw: string,\n sourceFiatRate: FiatRates,\n targetFiatRate: FiatRates,\n expectedOutputRaw?: string,\n): BigNumber {\n const totalFeeUsd = quote.fees?.total?.amountUsd;\n\n if (totalFeeUsd !== undefined) {\n return new BigNumber(totalFeeUsd).abs();\n }\n\n if (expectedOutputRaw === undefined) {\n return new BigNumber(0);\n }\n\n const expectedOutput = new BigNumber(expectedOutputRaw);\n\n if (expectedOutput.lte(0)) {\n return new BigNumber(0);\n }\n\n const inputAmountUsd = new BigNumber(inputAmountRaw)\n .shiftedBy(-quote.inputToken.decimals)\n .multipliedBy(sourceFiatRate.usdRate);\n const expectedOutputUsd = expectedOutput\n .shiftedBy(-quote.outputToken.decimals)\n .multipliedBy(targetFiatRate.usdRate);\n const providerFeeUsd = inputAmountUsd.minus(expectedOutputUsd);\n\n return providerFeeUsd.isNegative() ? new BigNumber(0) : providerFeeUsd;\n}\n\nfunction getAmountFromTokenAmount({\n amountRaw,\n decimals,\n fiatRate,\n}: {\n amountRaw: string;\n decimals: number;\n fiatRate: FiatRates;\n}): Amount {\n const rawValue = new BigNumber(amountRaw);\n const raw = rawValue.toString(10);\n\n const humanValue = rawValue.shiftedBy(-decimals);\n const human = humanValue.toString(10);\n\n const usd = humanValue.multipliedBy(fiatRate.usdRate).toString(10);\n const fiat = humanValue.multipliedBy(fiatRate.fiatRate).toString(10);\n\n return {\n fiat,\n human,\n raw,\n usd,\n };\n}\n\nasync function calculateSourceNetworkCost(\n quote: AcrossSwapApprovalResponse,\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n): Promise<{\n sourceNetwork: TransactionPayQuote<AcrossQuote>['fees']['sourceNetwork'];\n gasLimits: AcrossGasLimits;\n}> {\n const acrossFallbackGas =\n getPayStrategiesConfig(messenger).across.fallbackGas;\n const { from } = request;\n const approvalTxns = quote.approvalTxns ?? [];\n const { swapTx } = quote;\n const swapChainId = toHex(swapTx.chainId);\n\n const approvalGasResults = await Promise.all(\n approvalTxns.map(async (approval) => {\n const chainId = toHex(approval.chainId);\n const gas = await estimateGasLimit({\n chainId,\n data: approval.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: approval.to,\n value: approval.value ?? '0x0',\n });\n\n if (gas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: gas.error,\n transactionType: 'approval',\n });\n }\n\n return { chainId, gas };\n }),\n );\n\n const swapGasFromQuote = parseAcrossSwapGasLimit(swapTx.gas);\n const swapGas =\n swapGasFromQuote === undefined\n ? await estimateGasLimit({\n chainId: swapChainId,\n data: swapTx.data,\n fallbackGas: acrossFallbackGas,\n from,\n messenger,\n to: swapTx.to,\n value: swapTx.value ?? '0x0',\n })\n : {\n estimate: swapGasFromQuote,\n max: swapGasFromQuote,\n usedFallback: false,\n };\n\n if (swapGasFromQuote !== undefined) {\n log('Using Across-provided swap gas limit', {\n gas: swapGasFromQuote,\n transactionType: 'swap',\n });\n } else if (swapGas.usedFallback) {\n log('Gas estimate failed, using fallback', {\n error: swapGas.error,\n transactionType: 'swap',\n });\n }\n\n const estimate = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.estimate,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.estimate,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n const max = sumAmounts([\n ...approvalGasResults.map(({ chainId, gas }) =>\n calculateGasCost({\n chainId,\n gas: gas.max,\n isMax: true,\n messenger,\n }),\n ),\n calculateGasCost({\n chainId: swapChainId,\n gas: swapGas.max,\n isMax: true,\n maxFeePerGas: swapTx.maxFeePerGas,\n maxPriorityFeePerGas: swapTx.maxPriorityFeePerGas,\n messenger,\n }),\n ]);\n\n return {\n sourceNetwork: {\n estimate,\n max,\n },\n gasLimits: {\n approval: approvalGasResults.map(({ gas }) => ({\n estimate: gas.estimate,\n max: gas.max,\n })),\n swap: {\n estimate: swapGas.estimate,\n max: swapGas.max,\n },\n },\n };\n}\n\nfunction parseAcrossSwapGasLimit(gas?: string): number | undefined {\n if (!gas) {\n return undefined;\n }\n\n const parsedGas = gas.startsWith('0x')\n ? new BigNumber(gas.slice(2), 16)\n : new BigNumber(gas);\n\n if (\n !parsedGas.isFinite() ||\n parsedGas.isNaN() ||\n !parsedGas.isInteger() ||\n parsedGas.lte(0)\n ) {\n return undefined;\n }\n\n return parsedGas.toNumber();\n}\n"]}
|
|
@@ -280,7 +280,14 @@ export declare function getMessengerMock({ skipRegister, }?: {
|
|
|
280
280
|
} & {
|
|
281
281
|
location?: import("@metamask/bridge-controller").MetaMetricsSwapsEventSource | undefined;
|
|
282
282
|
ab_tests?: Record<string, string> | undefined;
|
|
283
|
-
|
|
283
|
+
active_ab_tests?: {
|
|
284
|
+
key: string;
|
|
285
|
+
value: string;
|
|
286
|
+
}[] | undefined;
|
|
287
|
+
}) | undefined, location?: import("@metamask/bridge-controller").MetaMetricsSwapsEventSource | undefined, abTests?: Record<string, string> | undefined, activeAbTests?: {
|
|
288
|
+
key: string;
|
|
289
|
+
value: string;
|
|
290
|
+
}[] | undefined) => Promise<import("@metamask/transaction-controller").TransactionMeta & Partial<import("../../../bridge-status-controller/src/types.cjs").SolanaTransactionMeta>>>;
|
|
284
291
|
updateTransactionMock: jest.MockedFn<(transactionMeta: import("@metamask/transaction-controller").TransactionMeta, note: string) => void>;
|
|
285
292
|
};
|
|
286
293
|
//# sourceMappingURL=messenger-mock.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messenger-mock.d.cts","sourceRoot":"","sources":["../../src/tests/messenger-mock.ts"],"names":[],"mappings":";AAyBA,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAW;AAY5D;;;;;;GAMG;AAEH,wBAAgB,gBAAgB,CAAC,EAC/B,YAAY,GACb,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO
|
|
1
|
+
{"version":3,"file":"messenger-mock.d.cts","sourceRoot":"","sources":["../../src/tests/messenger-mock.ts"],"names":[],"mappings":";AAyBA,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAW;AAY5D;;;;;;GAMG;AAEH,wBAAgB,gBAAgB,CAAC,EAC/B,YAAY,GACb,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqPjC"}
|
|
@@ -280,7 +280,14 @@ export declare function getMessengerMock({ skipRegister, }?: {
|
|
|
280
280
|
} & {
|
|
281
281
|
location?: import("@metamask/bridge-controller").MetaMetricsSwapsEventSource | undefined;
|
|
282
282
|
ab_tests?: Record<string, string> | undefined;
|
|
283
|
-
|
|
283
|
+
active_ab_tests?: {
|
|
284
|
+
key: string;
|
|
285
|
+
value: string;
|
|
286
|
+
}[] | undefined;
|
|
287
|
+
}) | undefined, location?: import("@metamask/bridge-controller").MetaMetricsSwapsEventSource | undefined, abTests?: Record<string, string> | undefined, activeAbTests?: {
|
|
288
|
+
key: string;
|
|
289
|
+
value: string;
|
|
290
|
+
}[] | undefined) => Promise<import("@metamask/transaction-controller").TransactionMeta & Partial<import("../../../bridge-status-controller/src/types.mjs").SolanaTransactionMeta>>>;
|
|
284
291
|
updateTransactionMock: jest.MockedFn<(transactionMeta: import("@metamask/transaction-controller").TransactionMeta, note: string) => void>;
|
|
285
292
|
};
|
|
286
293
|
//# sourceMappingURL=messenger-mock.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messenger-mock.d.mts","sourceRoot":"","sources":["../../src/tests/messenger-mock.ts"],"names":[],"mappings":";AAyBA,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAW;AAY5D;;;;;;GAMG;AAEH,wBAAgB,gBAAgB,CAAC,EAC/B,YAAY,GACb,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO
|
|
1
|
+
{"version":3,"file":"messenger-mock.d.mts","sourceRoot":"","sources":["../../src/tests/messenger-mock.ts"],"names":[],"mappings":";AAyBA,OAAO,KAAK,EAAE,iCAAiC,EAAE,qBAAW;AAY5D;;;;;;GAMG;AAEH,wBAAgB,gBAAgB,CAAC,EAC/B,YAAY,GACb,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqPjC"}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AppMetadataControllerGetStateAction } from '@metamask/app-metadata-controller';\nimport 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';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AppMetadataControllerGetStateAction\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\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update fiat payment state for a transaction. */\nexport type TransactionPayControllerUpdateFiatPaymentAction = {\n type: `${typeof CONTROLLER_NAME}:updateFiatPayment`;\n handler: (request: UpdateFiatPaymentRequest) => void;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\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 | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdateFiatPaymentAction\n | TransactionPayControllerUpdatePaymentTokenAction;\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 /** Callback to determine whether to use AssetsController for state. */\n getUseAssetsController?: () => boolean;\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 { AppMetadataControllerGetStateAction } from '@metamask/app-metadata-controller';\nimport 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';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AppMetadataControllerGetStateAction\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\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update fiat payment state for a transaction. */\nexport type TransactionPayControllerUpdateFiatPaymentAction = {\n type: `${typeof CONTROLLER_NAME}:updateFiatPayment`;\n handler: (request: UpdateFiatPaymentRequest) => void;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\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 | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdateFiatPaymentAction\n | TransactionPayControllerUpdatePaymentTokenAction;\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"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -81,8 +81,6 @@ export type TransactionPayControllerOptions = {
|
|
|
81
81
|
getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;
|
|
82
82
|
/** Callback to select ordered PayStrategies for a transaction. */
|
|
83
83
|
getStrategies?: (transaction: TransactionMeta) => TransactionPayStrategy[];
|
|
84
|
-
/** Callback to determine whether to use AssetsController for state. */
|
|
85
|
-
getUseAssetsController?: () => boolean;
|
|
86
84
|
/** Controller messenger. */
|
|
87
85
|
messenger: TransactionPayControllerMessenger;
|
|
88
86
|
/** Initial state of the controller. */
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,0CAA0C;AAC7F,OAAO,KAAK,EAAE,+CAA+C,EAAE,oCAAoC;AACnG,OAAO,KAAK,EACV,6BAA6B,EAC7B,qCAAqC,EACtC,qCAAqC;AACtC,OAAO,KAAK,EAAE,kCAAkC,EAAE,qCAAqC;AACvF,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAqC;AACnF,OAAO,KAAK,EAAE,sCAAsC,EAAE,qCAAqC;AAC3F,OAAO,KAAK,EAAE,0BAA0B,EAAE,kCAAkC;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC;AAC1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,oCAAoC;AAC3E,OAAO,KAAK,EAAE,sCAAsC,EAAE,2CAA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EAAE,eAAe,CAAC;CAC9B,KAAK,OAAO,CAAC;IACZ,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,EAAE,EAAE,GAAG,CAAC;IACR,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC,CAAC;AAEH,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG;IAC/B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IAEd,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -81,8 +81,6 @@ export type TransactionPayControllerOptions = {
|
|
|
81
81
|
getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;
|
|
82
82
|
/** Callback to select ordered PayStrategies for a transaction. */
|
|
83
83
|
getStrategies?: (transaction: TransactionMeta) => TransactionPayStrategy[];
|
|
84
|
-
/** Callback to determine whether to use AssetsController for state. */
|
|
85
|
-
getUseAssetsController?: () => boolean;
|
|
86
84
|
/** Controller messenger. */
|
|
87
85
|
messenger: TransactionPayControllerMessenger;
|
|
88
86
|
/** Initial state of the controller. */
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,0CAA0C;AAC7F,OAAO,KAAK,EAAE,+CAA+C,EAAE,oCAAoC;AACnG,OAAO,KAAK,EACV,6BAA6B,EAC7B,qCAAqC,EACtC,qCAAqC;AACtC,OAAO,KAAK,EAAE,kCAAkC,EAAE,qCAAqC;AACvF,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAqC;AACnF,OAAO,KAAK,EAAE,sCAAsC,EAAE,qCAAqC;AAC3F,OAAO,KAAK,EAAE,0BAA0B,EAAE,kCAAkC;AAC5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAA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,CAAC;AAEF,gEAAgE;AAChE,MAAM,MAAM,gCAAgC,GAAG,CAAC,EAC9C,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,eAAe,CAAC;CAC9B,KAAK,OAAO,CAAC;IACZ,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,EAAE,EAAE,GAAG,CAAC;IACR,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC,CAAC;AAEH,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG;IAC/B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IAEd,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AppMetadataControllerGetStateAction } from '@metamask/app-metadata-controller';\nimport 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';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AppMetadataControllerGetStateAction\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\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update fiat payment state for a transaction. */\nexport type TransactionPayControllerUpdateFiatPaymentAction = {\n type: `${typeof CONTROLLER_NAME}:updateFiatPayment`;\n handler: (request: UpdateFiatPaymentRequest) => void;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\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 | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdateFiatPaymentAction\n | TransactionPayControllerUpdatePaymentTokenAction;\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 /** Callback to determine whether to use AssetsController for state. */\n getUseAssetsController?: () => boolean;\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.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AppMetadataControllerGetStateAction } from '@metamask/app-metadata-controller';\nimport 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';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AppMetadataControllerGetStateAction\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\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update fiat payment state for a transaction. */\nexport type TransactionPayControllerUpdateFiatPaymentAction = {\n type: `${typeof CONTROLLER_NAME}:updateFiatPayment`;\n handler: (request: UpdateFiatPaymentRequest) => void;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\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 | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdateFiatPaymentAction\n | TransactionPayControllerUpdatePaymentTokenAction;\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/transaction-pay-controller",
|
|
3
|
-
"version": "16.4.1-preview-
|
|
3
|
+
"version": "16.4.1-preview-d8a0c2fc5",
|
|
4
4
|
"description": "Manages alternate payment strategies to provide required funds for transactions in MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -52,10 +52,11 @@
|
|
|
52
52
|
"@ethersproject/contracts": "^5.7.0",
|
|
53
53
|
"@ethersproject/providers": "^5.7.0",
|
|
54
54
|
"@metamask/app-metadata-controller": "^2.0.0",
|
|
55
|
-
"@metamask/assets-
|
|
55
|
+
"@metamask/assets-controller": "^2.3.0",
|
|
56
|
+
"@metamask/assets-controllers": "^100.2.1",
|
|
56
57
|
"@metamask/base-controller": "^9.0.0",
|
|
57
|
-
"@metamask/bridge-controller": "^69.
|
|
58
|
-
"@metamask/bridge-status-controller": "^68.0
|
|
58
|
+
"@metamask/bridge-controller": "^69.1.0",
|
|
59
|
+
"@metamask/bridge-status-controller": "^68.1.0",
|
|
59
60
|
"@metamask/controller-utils": "^11.19.0",
|
|
60
61
|
"@metamask/gas-fee-controller": "^26.0.3",
|
|
61
62
|
"@metamask/messenger": "^0.3.0",
|