@metamask/bridge-status-controller 68.1.0 → 70.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -1
- package/dist/bridge-status-controller.cjs +123 -221
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +1 -4
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +1 -4
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +9 -13
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +6 -8
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +6 -8
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +10 -14
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +125 -223
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/accounts.cjs +8 -0
- package/dist/utils/accounts.cjs.map +1 -0
- package/dist/utils/accounts.d.cts +36 -0
- package/dist/utils/accounts.d.cts.map +1 -0
- package/dist/utils/accounts.d.mts +36 -0
- package/dist/utils/accounts.d.mts.map +1 -0
- package/dist/utils/accounts.mjs +4 -0
- package/dist/utils/accounts.mjs.map +1 -0
- package/dist/utils/authentication.cjs +15 -0
- package/dist/utils/authentication.cjs.map +1 -0
- package/dist/utils/authentication.d.cts +3 -0
- package/dist/utils/authentication.d.cts.map +1 -0
- package/dist/utils/authentication.d.mts +3 -0
- package/dist/utils/authentication.d.mts.map +1 -0
- package/dist/utils/authentication.mjs +11 -0
- package/dist/utils/authentication.mjs.map +1 -0
- package/dist/utils/bridge-status.cjs +2 -4
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +2 -4
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/bridge.cjs +16 -0
- package/dist/utils/bridge.cjs.map +1 -0
- package/dist/utils/bridge.d.cts +10 -0
- package/dist/utils/bridge.d.cts.map +1 -0
- package/dist/utils/bridge.d.mts +10 -0
- package/dist/utils/bridge.d.mts.map +1 -0
- package/dist/utils/bridge.mjs +11 -0
- package/dist/utils/bridge.mjs.map +1 -0
- package/dist/utils/gas.cjs +4 -7
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +1 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +1 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +4 -7
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/history.cjs +97 -0
- package/dist/utils/history.cjs.map +1 -0
- package/dist/utils/history.d.cts +21 -0
- package/dist/utils/history.d.cts.map +1 -0
- package/dist/utils/history.d.mts +21 -0
- package/dist/utils/history.d.mts.map +1 -0
- package/dist/utils/history.mjs +90 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/intent-api.cjs +18 -3
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +16 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +16 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +18 -4
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/keyring.cjs +12 -0
- package/dist/utils/keyring.cjs.map +1 -0
- package/dist/utils/keyring.d.cts +8 -0
- package/dist/utils/keyring.d.cts.map +1 -0
- package/dist/utils/keyring.d.mts +8 -0
- package/dist/utils/keyring.d.mts.map +1 -0
- package/dist/utils/keyring.mjs +8 -0
- package/dist/utils/keyring.mjs.map +1 -0
- package/dist/utils/network.cjs +17 -0
- package/dist/utils/network.cjs.map +1 -0
- package/dist/utils/network.d.cts +5 -0
- package/dist/utils/network.d.cts.map +1 -0
- package/dist/utils/network.d.mts +5 -0
- package/dist/utils/network.d.mts.map +1 -0
- package/dist/utils/network.mjs +12 -0
- package/dist/utils/network.mjs.map +1 -0
- package/dist/utils/snaps.cjs +146 -1
- package/dist/utils/snaps.cjs.map +1 -1
- package/dist/utils/snaps.d.cts +62 -0
- package/dist/utils/snaps.d.cts.map +1 -1
- package/dist/utils/snaps.d.mts +62 -0
- package/dist/utils/snaps.d.mts.map +1 -1
- package/dist/utils/snaps.mjs +141 -0
- package/dist/utils/snaps.mjs.map +1 -1
- package/dist/utils/trace.cjs +31 -0
- package/dist/utils/trace.cjs.map +1 -0
- package/dist/utils/trace.d.cts +17 -0
- package/dist/utils/trace.d.cts.map +1 -0
- package/dist/utils/trace.d.mts +17 -0
- package/dist/utils/trace.d.mts.map +1 -0
- package/dist/utils/trace.mjs +26 -0
- package/dist/utils/trace.mjs.map +1 -0
- package/dist/utils/transaction.cjs +31 -193
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +8 -79
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +8 -79
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +31 -187
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.cjs +5 -5
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.d.cts +6 -11
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +6 -11
- package/dist/utils/validators.d.mts.map +1 -1
- package/dist/utils/validators.mjs +3 -3
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
import { ChainId, formatChainIdToHex } from "@metamask/bridge-controller";
|
|
2
3
|
import { toHex } from "@metamask/controller-utils";
|
|
3
4
|
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
|
4
5
|
import { createProjectLogger } from "@metamask/utils";
|
|
5
|
-
import {
|
|
6
|
+
import { getAccountByAddress } from "./accounts.mjs";
|
|
6
7
|
import { calculateGasFees } from "./gas.mjs";
|
|
7
|
-
import {
|
|
8
|
+
import { getNetworkClientIdByChainId } from "./network.mjs";
|
|
8
9
|
import { APPROVAL_DELAY_MS } from "../constants.mjs";
|
|
9
10
|
export const generateActionId = () => (Date.now() + Math.random()).toString();
|
|
10
11
|
export const getStatusRequestParams = (quoteResponse) => {
|
|
@@ -17,100 +18,6 @@ export const getStatusRequestParams = (quoteResponse) => {
|
|
|
17
18
|
refuel: Boolean(quoteResponse.quote.refuel),
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
|
-
export const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
|
21
|
-
// Handle destination chain ID - should always be convertible for EVM destinations
|
|
22
|
-
let destinationChainId;
|
|
23
|
-
try {
|
|
24
|
-
destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
// Fallback for non-EVM destination (shouldn't happen for BTC->EVM)
|
|
28
|
-
destinationChainId = '0x1'; // Default to mainnet
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
destinationChainId,
|
|
32
|
-
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
|
33
|
-
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
|
34
|
-
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
|
35
|
-
sourceTokenAddress: quoteResponse.quote.srcAsset.address,
|
|
36
|
-
destinationTokenAmount: quoteResponse.quote.destTokenAmount,
|
|
37
|
-
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
|
38
|
-
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
|
39
|
-
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
|
40
|
-
// chainId is now excluded from this function and handled by the caller
|
|
41
|
-
approvalTxId,
|
|
42
|
-
// this is the decimal (non atomic) amount (not USD value) of source token to swap
|
|
43
|
-
swapTokenValue: quoteResponse.sentAmount.amount,
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Handles the response from non-EVM transaction submission
|
|
48
|
-
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
49
|
-
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
50
|
-
*
|
|
51
|
-
* @param snapResponse - The response from the snap after transaction submission
|
|
52
|
-
* @param quoteResponse - The quote response containing trade details and metadata
|
|
53
|
-
* @param selectedAccount - The selected account information
|
|
54
|
-
* @returns The transaction metadata including non-EVM specific fields
|
|
55
|
-
*/
|
|
56
|
-
export const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
|
57
|
-
const selectedAccountAddress = selectedAccount.address;
|
|
58
|
-
const snapId = selectedAccount.metadata.snap?.id;
|
|
59
|
-
let hash;
|
|
60
|
-
// Handle different response formats
|
|
61
|
-
if (typeof snapResponse === 'string') {
|
|
62
|
-
hash = snapResponse;
|
|
63
|
-
}
|
|
64
|
-
else if (snapResponse && typeof snapResponse === 'object') {
|
|
65
|
-
// Check for new unified interface response format first
|
|
66
|
-
if ('transactionId' in snapResponse && snapResponse.transactionId) {
|
|
67
|
-
hash = snapResponse.transactionId;
|
|
68
|
-
}
|
|
69
|
-
else if ('result' in snapResponse &&
|
|
70
|
-
snapResponse.result &&
|
|
71
|
-
typeof snapResponse.result === 'object') {
|
|
72
|
-
// Try to extract signature from common locations in response object
|
|
73
|
-
hash =
|
|
74
|
-
snapResponse.result.signature ||
|
|
75
|
-
snapResponse.result.txid ||
|
|
76
|
-
snapResponse.result.hash ||
|
|
77
|
-
snapResponse.result.txHash;
|
|
78
|
-
}
|
|
79
|
-
else if ('signature' in snapResponse &&
|
|
80
|
-
snapResponse.signature &&
|
|
81
|
-
typeof snapResponse.signature === 'string') {
|
|
82
|
-
hash = snapResponse.signature;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
86
|
-
let hexChainId;
|
|
87
|
-
try {
|
|
88
|
-
hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
// TODO: Fix chain ID activity list handling for Bitcoin
|
|
92
|
-
// Fallback to Ethereum mainnet for now
|
|
93
|
-
hexChainId = '0x1';
|
|
94
|
-
}
|
|
95
|
-
// Extract the transaction data for storage
|
|
96
|
-
const tradeData = extractTradeData(quoteResponse.trade);
|
|
97
|
-
// Create a transaction meta object with bridge-specific fields
|
|
98
|
-
return {
|
|
99
|
-
...getTxMetaFields(quoteResponse),
|
|
100
|
-
time: Date.now(),
|
|
101
|
-
id: hash ?? uuid(),
|
|
102
|
-
chainId: hexChainId,
|
|
103
|
-
networkClientId: snapId ?? hexChainId,
|
|
104
|
-
txParams: { from: selectedAccountAddress, data: tradeData },
|
|
105
|
-
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
106
|
-
status: TransactionStatus.submitted,
|
|
107
|
-
hash, // Add the transaction signature as hash
|
|
108
|
-
origin: snapId,
|
|
109
|
-
// Add an explicit flag to mark this as a non-EVM transaction
|
|
110
|
-
isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains
|
|
111
|
-
isBridgeTx,
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
21
|
export const handleApprovalDelay = async (srcChainId) => {
|
|
115
22
|
if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {
|
|
116
23
|
const debugLog = createProjectLogger('bridge');
|
|
@@ -132,28 +39,6 @@ export const handleMobileHardwareWalletDelay = async (requireApproval) => {
|
|
|
132
39
|
await mobileHardwareWalletDelay;
|
|
133
40
|
}
|
|
134
41
|
};
|
|
135
|
-
/**
|
|
136
|
-
* Creates a request to sign and send a transaction for non-EVM chains
|
|
137
|
-
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
138
|
-
*
|
|
139
|
-
* @param trade - The trade data
|
|
140
|
-
* @param srcChainId - The source chain ID
|
|
141
|
-
* @param selectedAccount - The selected account information
|
|
142
|
-
* @returns The snap request object for signing and sending transaction
|
|
143
|
-
*/
|
|
144
|
-
export const getClientRequest = (trade, srcChainId, selectedAccount) => {
|
|
145
|
-
const scope = formatChainIdToCaip(srcChainId);
|
|
146
|
-
const transactionData = extractTradeData(trade);
|
|
147
|
-
// Tron trades need the visible flag and contract type to be included in the request options
|
|
148
|
-
const options = isTronTrade(trade)
|
|
149
|
-
? {
|
|
150
|
-
visible: trade.visible,
|
|
151
|
-
type: trade.raw_data?.contract?.[0]?.type,
|
|
152
|
-
}
|
|
153
|
-
: undefined;
|
|
154
|
-
// Use the new unified interface
|
|
155
|
-
return createClientTransactionRequest(selectedAccount.metadata.snap?.id, transactionData, scope, selectedAccount.id, options);
|
|
156
|
-
};
|
|
157
42
|
export const waitForTxConfirmation = async (messenger, txId, { timeoutMs = 5 * 60000, pollMs = 3000, } = {}) => {
|
|
158
43
|
const start = Date.now();
|
|
159
44
|
while (true) {
|
|
@@ -175,34 +60,14 @@ export const waitForTxConfirmation = async (messenger, txId, { timeoutMs = 5 * 6
|
|
|
175
60
|
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
176
61
|
}
|
|
177
62
|
};
|
|
178
|
-
export const
|
|
179
|
-
const historyItem = state.txHistory[actionId];
|
|
180
|
-
if (!historyItem) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
state.txHistory[txMeta.id] = {
|
|
184
|
-
...historyItem,
|
|
185
|
-
txMetaId: txMeta.id,
|
|
186
|
-
originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
|
|
187
|
-
status: {
|
|
188
|
-
...historyItem.status,
|
|
189
|
-
srcChain: {
|
|
190
|
-
...historyItem.status.srcChain,
|
|
191
|
-
txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
delete state.txHistory[actionId];
|
|
196
|
-
return true;
|
|
197
|
-
};
|
|
198
|
-
export const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
63
|
+
export const toBatchTxParams = (skipGasFields, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
199
64
|
const params = {
|
|
200
65
|
...trade,
|
|
201
66
|
data: trade.data,
|
|
202
67
|
to: trade.to,
|
|
203
68
|
value: trade.value,
|
|
204
69
|
};
|
|
205
|
-
if (
|
|
70
|
+
if (skipGasFields) {
|
|
206
71
|
return params;
|
|
207
72
|
}
|
|
208
73
|
return {
|
|
@@ -212,40 +77,43 @@ export const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, {
|
|
|
212
77
|
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),
|
|
213
78
|
};
|
|
214
79
|
};
|
|
215
|
-
export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false,
|
|
80
|
+
export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, gasSponsored, }, sentAmount, toTokenAmount, }, requireApproval = false, isDelegatedAccount = false, }) => {
|
|
216
81
|
const isGasless = gasIncluded || gasIncluded7702;
|
|
217
|
-
const selectedAccount = messenger
|
|
82
|
+
const selectedAccount = getAccountByAddress(messenger, trade.from);
|
|
218
83
|
if (!selectedAccount) {
|
|
219
84
|
throw new Error('Failed to submit cross-chain swap batch transaction: unknown account in trade data');
|
|
220
85
|
}
|
|
221
86
|
const hexChainId = formatChainIdToHex(trade.chainId);
|
|
222
|
-
const networkClientId = messenger
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
|
|
87
|
+
const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);
|
|
88
|
+
// Gas fields should be omitted only when gas is sponsored via 7702
|
|
89
|
+
const skipGasFields = gasIncluded7702 === true;
|
|
90
|
+
// Enable 7702 batching when the quote includes gasless 7702 support,
|
|
91
|
+
// or when the account is already delegated (to avoid the in-flight
|
|
92
|
+
// transaction limit for delegated accounts)
|
|
93
|
+
const disable7702 = !skipGasFields && !isDelegatedAccount;
|
|
226
94
|
const transactions = [];
|
|
227
95
|
if (resetApproval) {
|
|
228
|
-
const gasFees = await calculateGasFees(
|
|
96
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
229
97
|
transactions.push({
|
|
230
98
|
type: isBridgeTx
|
|
231
99
|
? TransactionType.bridgeApproval
|
|
232
100
|
: TransactionType.swapApproval,
|
|
233
|
-
params: toBatchTxParams(
|
|
101
|
+
params: toBatchTxParams(skipGasFields, resetApproval, gasFees),
|
|
234
102
|
});
|
|
235
103
|
}
|
|
236
104
|
if (approval) {
|
|
237
|
-
const gasFees = await calculateGasFees(
|
|
105
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
238
106
|
transactions.push({
|
|
239
107
|
type: isBridgeTx
|
|
240
108
|
? TransactionType.bridgeApproval
|
|
241
109
|
: TransactionType.swapApproval,
|
|
242
|
-
params: toBatchTxParams(
|
|
110
|
+
params: toBatchTxParams(skipGasFields, approval, gasFees),
|
|
243
111
|
});
|
|
244
112
|
}
|
|
245
|
-
const gasFees = await calculateGasFees(
|
|
113
|
+
const gasFees = await calculateGasFees(skipGasFields, messenger, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
246
114
|
transactions.push({
|
|
247
115
|
type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,
|
|
248
|
-
params: toBatchTxParams(
|
|
116
|
+
params: toBatchTxParams(skipGasFields, trade, gasFees),
|
|
249
117
|
assetsFiatValues: {
|
|
250
118
|
sending: sentAmount?.valueInCurrency?.toString(),
|
|
251
119
|
receiving: toTokenAmount?.valueInCurrency?.toString(),
|
|
@@ -263,7 +131,7 @@ export const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, appr
|
|
|
263
131
|
};
|
|
264
132
|
return transactionParams;
|
|
265
133
|
};
|
|
266
|
-
export const findAndUpdateTransactionsInBatch = ({ messenger,
|
|
134
|
+
export const findAndUpdateTransactionsInBatch = ({ messenger, batchId, txDataByType, }) => {
|
|
267
135
|
const txs = messenger.call('TransactionController:getState').transactions;
|
|
268
136
|
const txBatch = {
|
|
269
137
|
approvalMeta: undefined,
|
|
@@ -272,6 +140,10 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
272
140
|
// This is a workaround to update the tx type after the tx is signed
|
|
273
141
|
// TODO: remove this once the tx type for batch txs is preserved in the tx controller
|
|
274
142
|
Object.entries(txDataByType).forEach(([txType, txData]) => {
|
|
143
|
+
// Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)
|
|
144
|
+
if (txData === undefined) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
275
147
|
// Find transaction by batchId and either matching data or delegation characteristics
|
|
276
148
|
const txMeta = txs.find((tx) => {
|
|
277
149
|
if (tx.batchId !== batchId) {
|
|
@@ -285,12 +157,14 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
285
157
|
if (is7702Transaction) {
|
|
286
158
|
// For 7702 transactions, we need to match based on transaction type
|
|
287
159
|
// since the data field might be different (batch execute call)
|
|
288
|
-
if (txType === TransactionType.swap
|
|
160
|
+
if ((txType === TransactionType.swap ||
|
|
161
|
+
txType === TransactionType.bridge) &&
|
|
289
162
|
tx.type === TransactionType.batch) {
|
|
290
163
|
return true;
|
|
291
164
|
}
|
|
292
165
|
// Also check if it's an approval transaction for 7702
|
|
293
|
-
if (txType === TransactionType.swapApproval
|
|
166
|
+
if ((txType === TransactionType.swapApproval ||
|
|
167
|
+
txType === TransactionType.bridgeApproval) &&
|
|
294
168
|
tx.txParams.data === txData) {
|
|
295
169
|
return true;
|
|
296
170
|
}
|
|
@@ -300,7 +174,7 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
300
174
|
});
|
|
301
175
|
if (txMeta) {
|
|
302
176
|
const updatedTx = { ...txMeta, type: txType };
|
|
303
|
-
|
|
177
|
+
messenger.call('TransactionController:updateTransaction', updatedTx, `Update tx type to ${txType}`);
|
|
304
178
|
txBatch[[TransactionType.bridgeApproval, TransactionType.swapApproval].includes(txType)
|
|
305
179
|
? 'approvalMeta'
|
|
306
180
|
: 'tradeMeta'] = updatedTx;
|
|
@@ -308,34 +182,4 @@ export const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionF
|
|
|
308
182
|
});
|
|
309
183
|
return txBatch;
|
|
310
184
|
};
|
|
311
|
-
/**
|
|
312
|
-
* Determines the key to use for storing a bridge history item.
|
|
313
|
-
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
314
|
-
*
|
|
315
|
-
* @param actionId - The action ID used for pre-submission tracking
|
|
316
|
-
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
317
|
-
* @returns The key to use for the history item
|
|
318
|
-
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
319
|
-
*/
|
|
320
|
-
export function getHistoryKey(actionId, bridgeTxMetaId) {
|
|
321
|
-
const historyKey = actionId ?? bridgeTxMetaId;
|
|
322
|
-
if (!historyKey) {
|
|
323
|
-
throw new Error('Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided');
|
|
324
|
-
}
|
|
325
|
-
return historyKey;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Extracts and validates the intent data from a quote response.
|
|
329
|
-
*
|
|
330
|
-
* @param quoteResponse - The quote response that may contain intent data
|
|
331
|
-
* @returns The intent data from the quote
|
|
332
|
-
* @throws Error if the quote does not contain intent data
|
|
333
|
-
*/
|
|
334
|
-
export function getIntentFromQuote(quoteResponse) {
|
|
335
|
-
const { intent } = quoteResponse.quote;
|
|
336
|
-
if (!intent) {
|
|
337
|
-
throw new Error('submitIntent: missing intent data');
|
|
338
|
-
}
|
|
339
|
-
return intent;
|
|
340
|
-
}
|
|
341
185
|
//# sourceMappingURL=transaction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACb,oCAAoC;AAQrC,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,EACL,iBAAiB,EACjB,eAAe,EAChB,yCAAyC;AAM1C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB;AACtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,gBAAgB,EAAE,kBAAc;AACzC,OAAO,EAAE,8BAA8B,EAAE,oBAAgB;AAEzD,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AAOjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,G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YACX,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAyB,EAAE,CAAC;YACjE,mBAAmB,CAAC,SAAS,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAC;YAC9D,OAAO,CACL,CAAC,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,QAA4B,EAC5B,cAAkC;IAElC,MAAM,UAAU,GAAG,QAAQ,IAAI,cAAc,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,aAA6D;IAE7D,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC;IACvC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport {\n ChainId,\n extractTradeData,\n isTronTrade,\n formatChainIdToCaip,\n formatChainIdToHex,\n isCrossChain,\n} from '@metamask/bridge-controller';\nimport type {\n Intent,\n QuoteMetadata,\n QuoteResponse,\n Trade,\n TxData,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport { createClientTransactionRequest } from './snaps';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\nimport type { BridgeStatusControllerState } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (quoteResponse: QuoteResponse) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<Trade, Trade>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = '0x1' as `0x${string}`; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<QuoteResponse<Trade>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n // TODO: Fix chain ID activity list handling for Bitcoin\n // Fallback to Ethereum mainnet for now\n hexChainId = '0x1' as `0x${string}`;\n }\n\n // Extract the transaction data for storage\n const tradeData = extractTradeData(quoteResponse.trade);\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param trade - The trade data\n * @param srcChainId - The source chain ID\n * @param selectedAccount - The selected account information\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n trade: Trade,\n srcChainId: number,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const scope = formatChainIdToCaip(srcChainId);\n\n const transactionData = extractTradeData(trade);\n\n // Tron trades need the visible flag and contract type to be included in the request options\n const options = isTronTrade(trade)\n ? {\n visible: trade.visible,\n type: trade.raw_data?.contract?.[0]?.type,\n }\n : undefined;\n\n // Use the new unified interface\n return createClientTransactionRequest(\n selectedAccount.metadata.snap?.id as string,\n transactionData,\n scope,\n selectedAccount.id,\n options,\n );\n};\n\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const { transactions } = messenger.call('TransactionController:getState');\n const meta = transactions.find((tx: TransactionMeta) => tx.id === txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\nexport const toBatchTxParams = (\n disable7702: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (!disable7702) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n estimateGasFeeFn,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> &\n Partial<QuoteMetadata>;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messenger.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // When an active quote has gasIncluded7702 set to true,\n // enable 7702 gasless txs for smart accounts\n const disable7702 = gasIncluded7702 !== true;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(disable7702, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n isGasFeeSponsored: Boolean(gasSponsored),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n txType === TransactionType.swap &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n txType === TransactionType.swapApproval &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided',\n );\n }\n return historyKey;\n}\n\n/**\n * Extracts and validates the intent data from a quote response.\n *\n * @param quoteResponse - The quote response that may contain intent data\n * @returns The intent data from the quote\n * @throws Error if the quote does not contain intent data\n */\nexport function getIntentFromQuote(\n quoteResponse: QuoteResponse & { quote: { intent?: Intent } },\n): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,oCAAoC;AAM1E,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,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E,SAAS,CAAC,IAAI,CACZ,yCAAyC,EACzC,SAAS,EACT,qBAAqB,MAAM,EAAE,CAC9B,CAAC;YACF,OAAO,CACL,CAAC,eAAe,CAAC,cAAc,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { ChainId, formatChainIdToHex } from '@metamask/bridge-controller';\nimport type {\n QuoteMetadata,\n QuoteResponse,\n TxData,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransactionParams,\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { TransactionBatchSingleRequest } from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\n\nimport { getAccountByAddress } from './accounts';\nimport { calculateGasFees } from './gas';\nimport { getNetworkClientIdByChainId } from './network';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type { BridgeStatusControllerMessenger } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (quoteResponse: QuoteResponse) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const handleApprovalDelay = async (\n srcChainId: QuoteResponse['quote']['srcChainId'],\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\nexport const waitForTxConfirmation = async (\n messenger: BridgeStatusControllerMessenger,\n txId: string,\n {\n timeoutMs = 5 * 60_000,\n pollMs = 3_000,\n }: { timeoutMs?: number; pollMs?: number } = {},\n): Promise<TransactionMeta> => {\n const start = Date.now();\n while (true) {\n const { transactions } = messenger.call('TransactionController:getState');\n const meta = transactions.find((tx: TransactionMeta) => tx.id === txId);\n\n if (meta) {\n if (meta.status === TransactionStatus.confirmed) {\n return meta;\n }\n if (\n meta.status === TransactionStatus.failed ||\n meta.status === TransactionStatus.dropped ||\n meta.status === TransactionStatus.rejected\n ) {\n throw new Error('Approval transaction did not confirm');\n }\n }\n\n if (Date.now() - start > timeoutMs) {\n throw new Error('Timed out waiting for approval confirmation');\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollMs));\n }\n};\n\nexport const toBatchTxParams = (\n skipGasFields: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (skipGasFields) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n gasSponsored,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n isDelegatedAccount = false,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> &\n Partial<QuoteMetadata>;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n isDelegatedAccount?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = getAccountByAddress(messenger, trade.from);\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = getNetworkClientIdByChainId(messenger, hexChainId);\n\n // Gas fields should be omitted only when gas is sponsored via 7702\n const skipGasFields = gasIncluded7702 === true;\n // Enable 7702 batching when the quote includes gasless 7702 support,\n // or when the account is already delegated (to avoid the in-flight\n // transaction limit for delegated accounts)\n const disable7702 = !skipGasFields && !isDelegatedAccount;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(skipGasFields, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n skipGasFields,\n messenger,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(skipGasFields, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n isGasFeeSponsored: Boolean(gasSponsored),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Skip types not present in the batch (e.g. swap entry is undefined for bridge txs)\n if (txData === undefined) {\n return;\n }\n\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx: TransactionMeta) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n (txType === TransactionType.swap ||\n txType === TransactionType.bridge) &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n (txType === TransactionType.swapApproval ||\n txType === TransactionType.bridgeApproval) &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n messenger.call(\n 'TransactionController:updateTransaction',\n updatedTx,\n `Update tx type to ${txType}`,\n );\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateIntentStatusResponse = exports.IntentOrderStatus = exports.validateBridgeStatusResponse = exports.StatusResponseSchema = void 0;
|
|
4
4
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
6
6
|
const ChainIdSchema = (0, superstruct_1.number)();
|
|
@@ -52,7 +52,7 @@ var IntentOrderStatus;
|
|
|
52
52
|
IntentOrderStatus["CANCELLED"] = "cancelled";
|
|
53
53
|
IntentOrderStatus["EXPIRED"] = "expired";
|
|
54
54
|
})(IntentOrderStatus || (exports.IntentOrderStatus = IntentOrderStatus = {}));
|
|
55
|
-
|
|
55
|
+
const IntentStatusResponseSchema = (0, superstruct_1.type)({
|
|
56
56
|
id: (0, superstruct_1.string)(),
|
|
57
57
|
status: (0, superstruct_1.enums)(Object.values(IntentOrderStatus)),
|
|
58
58
|
txHash: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
@@ -60,8 +60,8 @@ exports.IntentOrderResponseSchema = (0, superstruct_1.type)({
|
|
|
60
60
|
txHashes: (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.array)((0, superstruct_1.string)()), (0, superstruct_1.string)()])),
|
|
61
61
|
}),
|
|
62
62
|
});
|
|
63
|
-
const
|
|
64
|
-
return (0, superstruct_1.is)(data,
|
|
63
|
+
const validateIntentStatusResponse = (data) => {
|
|
64
|
+
return (0, superstruct_1.is)(data, IntentStatusResponseSchema);
|
|
65
65
|
};
|
|
66
|
-
exports.
|
|
66
|
+
exports.validateIntentStatusResponse = validateIntentStatusResponse;
|
|
67
67
|
//# sourceMappingURL=validators.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":";;;AAAA,mEAA6E;AAE7E,uDAW+B;AAE/B,MAAM,aAAa,GAAG,IAAA,oBAAM,GAAE,CAAC;AAE/B,MAAM,iBAAiB,GAAG,IAAA,kBAAI,EAAC,EAAE,CAAC,CAAC;AAEnC,MAAM,oBAAoB,GAAG,IAAA,kBAAI,EAAC;IAChC,OAAO,EAAE,aAAa;IACtB;;;OAGG;IACH,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,iBAAiB,EAAE,qCAAiB,CAAC,CAAC,CAAC;CAC/D,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,IAAA,kBAAI,EAAC;IACjC,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B;;OAEG;IACH,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,iBAAiB,EAAE,qCAAiB,CAAC,CAAC,CAAC;CA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a,EAC+B,EAAE;IAC9C,IAAA,oBAAM,EAAC,IAAI,EAAE,4BAAoB,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,4BAA4B,gCAKvC;AAEF,IAAY,iBAQX;AARD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,wCAAmB,CAAA;AACrB,CAAC,EARW,iBAAiB,iCAAjB,iBAAiB,QAQ5B;AAED,MAAM,0BAA0B,GAAG,IAAA,kBAAI,EAAC;IACtC,EAAE,EAAE,IAAA,oBAAM,GAAE;IACZ,MAAM,EAAE,IAAA,mBAAK,EAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC/C,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,QAAQ,EAAE,IAAA,kBAAI,EAAC;QACb,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC,CAAC;KACvD,CAAC;CACH,CAAC,CAAC;AAII,MAAM,4BAA4B,GAAG,CAC1C,IAAa,EACiB,EAAE;IAChC,OAAO,IAAA,gBAAE,EAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC;AAJW,QAAA,4BAA4B,gCAIvC","sourcesContent":["import { StatusTypes, BridgeAssetSchema } from '@metamask/bridge-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n string,\n boolean,\n number,\n optional,\n enums,\n union,\n type,\n assert,\n array,\n is,\n} from '@metamask/superstruct';\n\nconst ChainIdSchema = number();\n\nconst EmptyObjectSchema = type({});\n\nconst SrcChainStatusSchema = type({\n chainId: ChainIdSchema,\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash: optional(string()),\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst DestChainStatusSchema = type({\n chainId: ChainIdSchema,\n txHash: optional(string()),\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst RefuelStatusResponseSchema = type({});\n\nexport const StatusResponseSchema = type({\n status: enums(Object.values(StatusTypes)),\n srcChain: SrcChainStatusSchema,\n destChain: optional(DestChainStatusSchema),\n bridge: optional(string()),\n isExpectedToken: optional(boolean()),\n isUnrecognizedRouterAddress: optional(boolean()),\n refuel: optional(RefuelStatusResponseSchema),\n});\n\nexport const validateBridgeStatusResponse = (\n data: unknown,\n): data is Infer<typeof StatusResponseSchema> => {\n assert(data, StatusResponseSchema);\n return true;\n};\n\nexport enum IntentOrderStatus {\n PENDING = 'pending',\n SUBMITTED = 'submitted',\n CONFIRMED = 'confirmed',\n COMPLETED = 'completed',\n FAILED = 'failed',\n CANCELLED = 'cancelled',\n EXPIRED = 'expired',\n}\n\nconst IntentStatusResponseSchema = type({\n id: string(),\n status: enums(Object.values(IntentOrderStatus)),\n txHash: optional(string()),\n metadata: type({\n txHashes: optional(union([array(string()), string()])),\n }),\n});\n\nexport type IntentStatusResponse = Infer<typeof IntentStatusResponseSchema>;\n\nexport const validateIntentStatusResponse = (\n data: unknown,\n): data is IntentStatusResponse => {\n return is(data, IntentStatusResponseSchema);\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StatusTypes } from "@metamask/bridge-controller";
|
|
2
|
+
import type { Infer } from "@metamask/superstruct";
|
|
2
3
|
export declare const StatusResponseSchema: import("@metamask/superstruct").Struct<{
|
|
3
4
|
status: StatusTypes;
|
|
4
5
|
srcChain: {
|
|
@@ -162,17 +163,9 @@ export declare enum IntentOrderStatus {
|
|
|
162
163
|
CANCELLED = "cancelled",
|
|
163
164
|
EXPIRED = "expired"
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
+
declare const IntentStatusResponseSchema: import("@metamask/superstruct").Struct<{
|
|
166
167
|
id: string;
|
|
167
168
|
status: IntentOrderStatus;
|
|
168
|
-
txHash?: string;
|
|
169
|
-
metadata: {
|
|
170
|
-
txHashes?: string[] | string;
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
export declare const IntentOrderResponseSchema: import("@metamask/superstruct").Struct<{
|
|
174
|
-
status: IntentOrderStatus;
|
|
175
|
-
id: string;
|
|
176
169
|
metadata: {
|
|
177
170
|
txHashes?: string | string[] | undefined;
|
|
178
171
|
};
|
|
@@ -195,12 +188,14 @@ export declare const IntentOrderResponseSchema: import("@metamask/superstruct").
|
|
|
195
188
|
txHashes: import("@metamask/superstruct").Struct<string | string[] | undefined, null>;
|
|
196
189
|
}>;
|
|
197
190
|
}>;
|
|
198
|
-
export
|
|
199
|
-
|
|
191
|
+
export type IntentStatusResponse = Infer<typeof IntentStatusResponseSchema>;
|
|
192
|
+
export declare const validateIntentStatusResponse: (data: unknown) => data is {
|
|
200
193
|
id: string;
|
|
194
|
+
status: IntentOrderStatus;
|
|
201
195
|
metadata: {
|
|
202
196
|
txHashes?: string | string[] | undefined;
|
|
203
197
|
};
|
|
204
198
|
txHash?: string | undefined;
|
|
205
199
|
};
|
|
200
|
+
export {};
|
|
206
201
|
//# sourceMappingURL=validators.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;
|
|
1
|
+
{"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AA4CnD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAxB/B;;;WAGG;;QAEH;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAQH;;WAEG;;;;;;;;;;;;;;;;;EAeH,CAAC;AAEH,eAAO,MAAM,4BAA4B,SACjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAId,CAAC;AAEF,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,OAAO,YAAY;CACpB;AAED,QAAA,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;EAO9B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE5E,eAAO,MAAM,4BAA4B,SACjC,OAAO;;;;;;;CAGd,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StatusTypes } from "@metamask/bridge-controller";
|
|
2
|
+
import type { Infer } from "@metamask/superstruct";
|
|
2
3
|
export declare const StatusResponseSchema: import("@metamask/superstruct").Struct<{
|
|
3
4
|
status: StatusTypes;
|
|
4
5
|
srcChain: {
|
|
@@ -162,17 +163,9 @@ export declare enum IntentOrderStatus {
|
|
|
162
163
|
CANCELLED = "cancelled",
|
|
163
164
|
EXPIRED = "expired"
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
+
declare const IntentStatusResponseSchema: import("@metamask/superstruct").Struct<{
|
|
166
167
|
id: string;
|
|
167
168
|
status: IntentOrderStatus;
|
|
168
|
-
txHash?: string;
|
|
169
|
-
metadata: {
|
|
170
|
-
txHashes?: string[] | string;
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
export declare const IntentOrderResponseSchema: import("@metamask/superstruct").Struct<{
|
|
174
|
-
status: IntentOrderStatus;
|
|
175
|
-
id: string;
|
|
176
169
|
metadata: {
|
|
177
170
|
txHashes?: string | string[] | undefined;
|
|
178
171
|
};
|
|
@@ -195,12 +188,14 @@ export declare const IntentOrderResponseSchema: import("@metamask/superstruct").
|
|
|
195
188
|
txHashes: import("@metamask/superstruct").Struct<string | string[] | undefined, null>;
|
|
196
189
|
}>;
|
|
197
190
|
}>;
|
|
198
|
-
export
|
|
199
|
-
|
|
191
|
+
export type IntentStatusResponse = Infer<typeof IntentStatusResponseSchema>;
|
|
192
|
+
export declare const validateIntentStatusResponse: (data: unknown) => data is {
|
|
200
193
|
id: string;
|
|
194
|
+
status: IntentOrderStatus;
|
|
201
195
|
metadata: {
|
|
202
196
|
txHashes?: string | string[] | undefined;
|
|
203
197
|
};
|
|
204
198
|
txHash?: string | undefined;
|
|
205
199
|
};
|
|
200
|
+
export {};
|
|
206
201
|
//# sourceMappingURL=validators.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;
|
|
1
|
+
{"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqB,oCAAoC;AAC7E,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AA4CnD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAxB/B;;;WAGG;;QAEH;;WAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAQH;;WAEG;;;;;;;;;;;;;;;;;EAeH,CAAC;AAEH,eAAO,MAAM,4BAA4B,SACjC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAId,CAAC;AAEF,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,OAAO,YAAY;CACpB;AAED,QAAA,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;EAO9B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE5E,eAAO,MAAM,4BAA4B,SACjC,OAAO;;;;;;;CAGd,CAAC"}
|
|
@@ -48,7 +48,7 @@ export var IntentOrderStatus;
|
|
|
48
48
|
IntentOrderStatus["CANCELLED"] = "cancelled";
|
|
49
49
|
IntentOrderStatus["EXPIRED"] = "expired";
|
|
50
50
|
})(IntentOrderStatus || (IntentOrderStatus = {}));
|
|
51
|
-
|
|
51
|
+
const IntentStatusResponseSchema = type({
|
|
52
52
|
id: string(),
|
|
53
53
|
status: enums(Object.values(IntentOrderStatus)),
|
|
54
54
|
txHash: optional(string()),
|
|
@@ -56,7 +56,7 @@ export const IntentOrderResponseSchema = type({
|
|
|
56
56
|
txHashes: optional(union([array(string()), string()])),
|
|
57
57
|
}),
|
|
58
58
|
});
|
|
59
|
-
export const
|
|
60
|
-
return is(data,
|
|
59
|
+
export const validateIntentStatusResponse = (data) => {
|
|
60
|
+
return is(data, IntentStatusResponseSchema);
|
|
61
61
|
};
|
|
62
62
|
//# sourceMappingURL=validators.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.mjs","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,oCAAoC;AAE7E,OAAO,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,EAAE,EACH,8BAA8B;AAE/B,MAAM,aAAa,GAAG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AAC,CAAC;KACvD,CAAC;CACH,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,IAAa,EACiB,EAAE;IAChC,OAAO,EAAE,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;AAC9C,CAAC,CAAC","sourcesContent":["import { StatusTypes, BridgeAssetSchema } from '@metamask/bridge-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n string,\n boolean,\n number,\n optional,\n enums,\n union,\n type,\n assert,\n array,\n is,\n} from '@metamask/superstruct';\n\nconst ChainIdSchema = number();\n\nconst EmptyObjectSchema = type({});\n\nconst SrcChainStatusSchema = type({\n chainId: ChainIdSchema,\n /**\n * The txHash of the transaction on the source chain.\n * This might be undefined for smart transactions (STX)\n */\n txHash: optional(string()),\n /**\n * The atomic amount of the token sent minus fees on the source chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst DestChainStatusSchema = type({\n chainId: ChainIdSchema,\n txHash: optional(string()),\n /**\n * The atomic amount of the token received on the destination chain\n */\n amount: optional(string()),\n token: optional(union([EmptyObjectSchema, BridgeAssetSchema])),\n});\n\nconst RefuelStatusResponseSchema = type({});\n\nexport const StatusResponseSchema = type({\n status: enums(Object.values(StatusTypes)),\n srcChain: SrcChainStatusSchema,\n destChain: optional(DestChainStatusSchema),\n bridge: optional(string()),\n isExpectedToken: optional(boolean()),\n isUnrecognizedRouterAddress: optional(boolean()),\n refuel: optional(RefuelStatusResponseSchema),\n});\n\nexport const validateBridgeStatusResponse = (\n data: unknown,\n): data is Infer<typeof StatusResponseSchema> => {\n assert(data, StatusResponseSchema);\n return true;\n};\n\nexport enum IntentOrderStatus {\n PENDING = 'pending',\n SUBMITTED = 'submitted',\n CONFIRMED = 'confirmed',\n COMPLETED = 'completed',\n FAILED = 'failed',\n CANCELLED = 'cancelled',\n EXPIRED = 'expired',\n}\n\nconst IntentStatusResponseSchema = type({\n id: string(),\n status: enums(Object.values(IntentOrderStatus)),\n txHash: optional(string()),\n metadata: type({\n txHashes: optional(union([array(string()), string()])),\n }),\n});\n\nexport type IntentStatusResponse = Infer<typeof IntentStatusResponseSchema>;\n\nexport const validateIntentStatusResponse = (\n data: unknown,\n): data is IntentStatusResponse => {\n return is(data, IntentStatusResponseSchema);\n};\n"]}
|