@metamask/bridge-status-controller 71.2.1 → 72.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.
Files changed (126) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/dist/bridge-status-controller-method-action-types.cjs.map +1 -1
  3. package/dist/bridge-status-controller-method-action-types.d.cts +5 -1
  4. package/dist/bridge-status-controller-method-action-types.d.cts.map +1 -1
  5. package/dist/bridge-status-controller-method-action-types.d.mts +5 -1
  6. package/dist/bridge-status-controller-method-action-types.d.mts.map +1 -1
  7. package/dist/bridge-status-controller-method-action-types.mjs.map +1 -1
  8. package/dist/bridge-status-controller.cjs +161 -366
  9. package/dist/bridge-status-controller.cjs.map +1 -1
  10. package/dist/bridge-status-controller.d.cts +27 -7
  11. package/dist/bridge-status-controller.d.cts.map +1 -1
  12. package/dist/bridge-status-controller.d.mts +27 -7
  13. package/dist/bridge-status-controller.d.mts.map +1 -1
  14. package/dist/bridge-status-controller.mjs +162 -370
  15. package/dist/bridge-status-controller.mjs.map +1 -1
  16. package/dist/index.cjs +4 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -0
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +1 -0
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +1 -0
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/strategy/batch-sell-strategy.cjs +101 -0
  25. package/dist/strategy/batch-sell-strategy.cjs.map +1 -0
  26. package/dist/strategy/batch-sell-strategy.d.cts +10 -0
  27. package/dist/strategy/batch-sell-strategy.d.cts.map +1 -0
  28. package/dist/strategy/batch-sell-strategy.d.mts +10 -0
  29. package/dist/strategy/batch-sell-strategy.d.mts.map +1 -0
  30. package/dist/strategy/batch-sell-strategy.mjs +97 -0
  31. package/dist/strategy/batch-sell-strategy.mjs.map +1 -0
  32. package/dist/strategy/batch-strategy.cjs +64 -0
  33. package/dist/strategy/batch-strategy.cjs.map +1 -0
  34. package/dist/strategy/batch-strategy.d.cts +10 -0
  35. package/dist/strategy/batch-strategy.d.cts.map +1 -0
  36. package/dist/strategy/batch-strategy.d.mts +10 -0
  37. package/dist/strategy/batch-strategy.d.mts.map +1 -0
  38. package/dist/strategy/batch-strategy.mjs +60 -0
  39. package/dist/strategy/batch-strategy.mjs.map +1 -0
  40. package/dist/strategy/evm-strategy.cjs +149 -0
  41. package/dist/strategy/evm-strategy.cjs.map +1 -0
  42. package/dist/strategy/evm-strategy.d.cts +38 -0
  43. package/dist/strategy/evm-strategy.d.cts.map +1 -0
  44. package/dist/strategy/evm-strategy.d.mts +38 -0
  45. package/dist/strategy/evm-strategy.d.mts.map +1 -0
  46. package/dist/strategy/evm-strategy.mjs +143 -0
  47. package/dist/strategy/evm-strategy.mjs.map +1 -0
  48. package/dist/strategy/index.cjs +70 -0
  49. package/dist/strategy/index.cjs.map +1 -0
  50. package/dist/strategy/index.d.cts +12 -0
  51. package/dist/strategy/index.d.cts.map +1 -0
  52. package/dist/strategy/index.d.mts +12 -0
  53. package/dist/strategy/index.d.mts.map +1 -0
  54. package/dist/strategy/index.mjs +68 -0
  55. package/dist/strategy/index.mjs.map +1 -0
  56. package/dist/strategy/intent-strategy.cjs +160 -0
  57. package/dist/strategy/intent-strategy.cjs.map +1 -0
  58. package/dist/strategy/intent-strategy.d.cts +17 -0
  59. package/dist/strategy/intent-strategy.d.cts.map +1 -0
  60. package/dist/strategy/intent-strategy.d.mts +17 -0
  61. package/dist/strategy/intent-strategy.d.mts.map +1 -0
  62. package/dist/strategy/intent-strategy.mjs +156 -0
  63. package/dist/strategy/intent-strategy.mjs.map +1 -0
  64. package/dist/strategy/non-evm-strategy.cjs +80 -0
  65. package/dist/strategy/non-evm-strategy.cjs.map +1 -0
  66. package/dist/strategy/non-evm-strategy.d.cts +15 -0
  67. package/dist/strategy/non-evm-strategy.d.cts.map +1 -0
  68. package/dist/strategy/non-evm-strategy.d.mts +15 -0
  69. package/dist/strategy/non-evm-strategy.d.mts.map +1 -0
  70. package/dist/strategy/non-evm-strategy.mjs +76 -0
  71. package/dist/strategy/non-evm-strategy.mjs.map +1 -0
  72. package/dist/strategy/types.cjs +13 -0
  73. package/dist/strategy/types.cjs.map +1 -0
  74. package/dist/strategy/types.d.cts +77 -0
  75. package/dist/strategy/types.d.cts.map +1 -0
  76. package/dist/strategy/types.d.mts +77 -0
  77. package/dist/strategy/types.d.mts.map +1 -0
  78. package/dist/strategy/types.mjs +10 -0
  79. package/dist/strategy/types.mjs.map +1 -0
  80. package/dist/types.cjs.map +1 -1
  81. package/dist/types.d.cts +41 -6
  82. package/dist/types.d.cts.map +1 -1
  83. package/dist/types.d.mts +41 -6
  84. package/dist/types.d.mts.map +1 -1
  85. package/dist/types.mjs.map +1 -1
  86. package/dist/utils/bridge.cjs +5 -1
  87. package/dist/utils/bridge.cjs.map +1 -1
  88. package/dist/utils/bridge.d.cts +2 -2
  89. package/dist/utils/bridge.d.cts.map +1 -1
  90. package/dist/utils/bridge.d.mts +2 -2
  91. package/dist/utils/bridge.d.mts.map +1 -1
  92. package/dist/utils/bridge.mjs +3 -0
  93. package/dist/utils/bridge.mjs.map +1 -1
  94. package/dist/utils/history.cjs +72 -20
  95. package/dist/utils/history.cjs.map +1 -1
  96. package/dist/utils/history.d.cts +19 -5
  97. package/dist/utils/history.d.cts.map +1 -1
  98. package/dist/utils/history.d.mts +19 -5
  99. package/dist/utils/history.d.mts.map +1 -1
  100. package/dist/utils/history.mjs +69 -19
  101. package/dist/utils/history.mjs.map +1 -1
  102. package/dist/utils/metrics.cjs +10 -7
  103. package/dist/utils/metrics.cjs.map +1 -1
  104. package/dist/utils/metrics.d.cts +7 -6
  105. package/dist/utils/metrics.d.cts.map +1 -1
  106. package/dist/utils/metrics.d.mts +7 -6
  107. package/dist/utils/metrics.d.mts.map +1 -1
  108. package/dist/utils/metrics.mjs +10 -7
  109. package/dist/utils/metrics.mjs.map +1 -1
  110. package/dist/utils/trace.cjs +4 -4
  111. package/dist/utils/trace.cjs.map +1 -1
  112. package/dist/utils/trace.d.cts +2 -2
  113. package/dist/utils/trace.d.cts.map +1 -1
  114. package/dist/utils/trace.d.mts +2 -2
  115. package/dist/utils/trace.d.mts.map +1 -1
  116. package/dist/utils/trace.mjs +4 -4
  117. package/dist/utils/trace.mjs.map +1 -1
  118. package/dist/utils/transaction.cjs +223 -252
  119. package/dist/utils/transaction.cjs.map +1 -1
  120. package/dist/utils/transaction.d.cts +68 -147
  121. package/dist/utils/transaction.d.cts.map +1 -1
  122. package/dist/utils/transaction.d.mts +68 -147
  123. package/dist/utils/transaction.d.mts.map +1 -1
  124. package/dist/utils/transaction.mjs +214 -247
  125. package/dist/utils/transaction.mjs.map +1 -1
  126. package/package.json +2 -2
@@ -0,0 +1,156 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ import { formatChainIdToHex, isEvmTxData } from "@metamask/bridge-controller";
3
+ import { TransactionType } from "@metamask/transaction-controller";
4
+ import { getJwt } from "../utils/authentication.mjs";
5
+ import { getIntentFromQuote, mapIntentOrderStatusToTransactionStatus, postSubmitOrder } from "../utils/intent-api.mjs";
6
+ import { signTypedMessage } from "../utils/keyring.mjs";
7
+ import { getNetworkClientIdByChainId } from "../utils/network.mjs";
8
+ import { addSyntheticTransaction, waitForTxConfirmation } from "../utils/transaction.mjs";
9
+ import { handleEvmApprovals } from "./evm-strategy.mjs";
10
+ import { SubmitStep } from "./types.mjs";
11
+ /**
12
+ * Submits a synthetic EVM transaction to the TransactionController in order to display the intent order's
13
+ * status in theclients, before the actual transaction is finalized on chain. The resulting transaction
14
+ * is only available locally and is not submitted to the chain.
15
+ *
16
+ * @param orderUid - The order uid of the intent transaction
17
+ * @param args - The parameters for the transaction
18
+ * @returns The tradeMeta for the synthetic transaction
19
+ */
20
+ const handleSyntheticTx = async (orderUid, args) => {
21
+ const { quoteResponses: [quoteResponse], messenger, isBridgeTx, selectedAccount, } = args;
22
+ const { quote: { srcChainId }, } = quoteResponse;
23
+ // Determine transaction type: swap for same-chain, bridge for cross-chain
24
+ const transactionType = isBridgeTx
25
+ ? /* c8 ignore start */
26
+ TransactionType.bridge
27
+ : /* c8 ignore end */
28
+ TransactionType.swap;
29
+ const networkClientId = getNetworkClientIdByChainId(messenger, srcChainId);
30
+ // This is a synthetic transaction whose purpose is to be able
31
+ // to track the order status via the history
32
+ if (!isEvmTxData(quoteResponse.trade)) {
33
+ throw new Error('Failed to submit intent: trade is not an EVM transaction');
34
+ }
35
+ const intent = getIntentFromQuote(quoteResponse);
36
+ // This is a synthetic transaction whose purpose is to be able
37
+ // to track the order status via the history
38
+ /**
39
+ * @deprecated use trade data from quote response instead
40
+ */
41
+ const intentTransactionParams = {
42
+ chainId: formatChainIdToHex(srcChainId),
43
+ from: selectedAccount.address,
44
+ to: intent.settlementContract ?? '0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
45
+ data: `0x${orderUid?.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique
46
+ value: '0x0',
47
+ gas: '0x5208', // Minimal gas for display purposes
48
+ gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it
49
+ };
50
+ const initialTxMeta = await addSyntheticTransaction(messenger, intentTransactionParams, {
51
+ requireApproval: false,
52
+ networkClientId,
53
+ type: transactionType,
54
+ });
55
+ return initialTxMeta;
56
+ };
57
+ /**
58
+ * Submits batched EVM transactions to the TransactionController
59
+ *
60
+ * @param args - The parameters for the transaction
61
+ * @param args.quoteResponse - The quote response
62
+ * @param args.messenger - The messenger
63
+ * @param args.selectedAccount - The selected account
64
+ * @param args.traceFn - The trace function
65
+ * @param args.isBridgeTx - Whether the transaction is a bridge transaction
66
+ * @returns The approvalTxId and tradeMeta for the non-EVM transaction
67
+ */
68
+ const handleSubmitIntent = async (args) => {
69
+ const { quoteResponses: [quoteResponse], messenger, selectedAccount, clientId, fetchFn, bridgeApiBaseUrl, } = args;
70
+ const { srcChainId, requestId } = quoteResponse.quote;
71
+ const intent = getIntentFromQuote(quoteResponse);
72
+ const signature = await signTypedMessage({
73
+ messenger,
74
+ accountAddress: selectedAccount.address,
75
+ typedData: intent.typedData,
76
+ });
77
+ const { id: orderUid, status } = await postSubmitOrder({
78
+ params: {
79
+ srcChainId,
80
+ quoteId: requestId,
81
+ signature,
82
+ order: intent.order,
83
+ userAddress: selectedAccount.address,
84
+ aggregatorId: intent.protocol,
85
+ },
86
+ clientId,
87
+ jwt: await getJwt(messenger),
88
+ fetchFn,
89
+ bridgeApiBaseUrl,
90
+ });
91
+ return {
92
+ orderUid,
93
+ orderStatus: status,
94
+ };
95
+ };
96
+ /**
97
+ * Submits an approval tx to the TransactionController,
98
+ * posts an intent order to the bridge-api,
99
+ * and creates a synthetic transaction in the TransactionController
100
+ *
101
+ * @param args - The parameters for the transaction
102
+ * @param args.quoteResponse - The quote response
103
+ * @param args.messenger - The messenger
104
+ * @param args.selectedAccount - The selected account
105
+ * @param args.traceFn - The trace function
106
+ * @param args.isBridgeTx - Whether the transaction is a bridge transaction
107
+ * @yields The approvalTxId and tradeMeta for the intent transaction
108
+ */
109
+ export async function* submitIntentHandler(args) {
110
+ // TODO handle STX/batch approvals
111
+ const approvalTxId = await handleEvmApprovals(args);
112
+ approvalTxId && (await waitForTxConfirmation(args.messenger, approvalTxId));
113
+ // TODO add to history after approval tx is confirmed
114
+ // Submit the intent order to the bridge-api
115
+ const { orderUid, orderStatus } = await handleSubmitIntent(args);
116
+ // Initialize a transaction in the TransactionController
117
+ const syntheticTxMeta = await handleSyntheticTx(orderUid, {
118
+ ...args,
119
+ requireApproval: false,
120
+ isStxEnabled: false,
121
+ });
122
+ // Use synthetic transaction metadata + translated intent order status as the tradeMeta
123
+ yield {
124
+ type: SubmitStep.SetTradeMeta,
125
+ payload: {
126
+ tradeMeta: {
127
+ ...syntheticTxMeta,
128
+ // Map intent order status to TransactionController status
129
+ status: mapIntentOrderStatusToTransactionStatus(orderStatus),
130
+ },
131
+ },
132
+ };
133
+ // Update txHistory with synthetic txMeta and order id
134
+ yield {
135
+ type: SubmitStep.AddHistoryItem,
136
+ payload: {
137
+ // Use orderId as the history key for intent transactions
138
+ historyKey: orderUid,
139
+ bridgeTxMeta: {
140
+ id: syntheticTxMeta?.id,
141
+ },
142
+ approvalTxId,
143
+ // Keep original txId for TransactionController updates
144
+ originalTransactionId: syntheticTxMeta?.id,
145
+ quoteResponse: args.quoteResponses[0],
146
+ },
147
+ };
148
+ // Start polling using the orderId as the history key
149
+ yield {
150
+ type: SubmitStep.StartPolling,
151
+ payload: {
152
+ historyKey: orderUid,
153
+ },
154
+ };
155
+ }
156
+ //# sourceMappingURL=intent-strategy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intent-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/intent-strategy.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EACL,kBAAkB,EAClB,WAAW,EAEZ,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,EAAE,MAAM,EAAE,oCAAgC;AACjD,OAAO,EACL,kBAAkB,EAClB,uCAAuC,EACvC,eAAe,EAChB,gCAA4B;AAC7B,OAAO,EAAE,gBAAgB,EAAE,6BAAyB;AACpD,OAAO,EAAE,2BAA2B,EAAE,6BAAyB;AAC/D,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACtB,iCAA6B;AAC9B,OAAO,EAAE,kBAAkB,EAAE,2BAAuB;AACpD,OAAO,EAA0C,UAAU,EAAE,oBAAgB;AAE7E;;;;;;;;GAQG;AACH,MAAM,iBAAiB,GAAG,KAAK,EAC7B,QAAgB,EAChB,IAA0B,EAC1B,EAAE;IACF,MAAM,EACJ,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,SAAS,EACT,UAAU,EACV,eAAe,GAChB,GAAG,IAAI,CAAC;IACT,MAAM,EACJ,KAAK,EAAE,EAAE,UAAU,EAAE,GACtB,GAAG,aAAa,CAAC;IAElB,0E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,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,uFAAuF;IACvF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,SAAS,EAAE;gBACT,GAAG,eAAe;gBAClB,0DAA0D;gBAC1D,MAAM,EAAE,uCAAuC,CAAC,WAAW,CAAC;aAC7D;SACF;KACF,CAAC;IAEF,sDAAsD;IACtD,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,cAAc;QAC/B,OAAO,EAAE;YACP,yDAAyD;YACzD,UAAU,EAAE,QAAQ;YACpB,YAAY,EAAE;gBACZ,EAAE,EAAE,eAAe,EAAE,EAAE;aACxB;YACD,YAAY;YACZ,uDAAuD;YACvD,qBAAqB,EAAE,eAAe,EAAE,EAAE;YAC1C,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;SACtC;KACF,CAAC;IAEF,qDAAqD;IACrD,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,UAAU,EAAE,QAAQ;SACrB;KACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport {\n formatChainIdToHex,\n isEvmTxData,\n TxData,\n} from '@metamask/bridge-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\n\nimport { getJwt } from '../utils/authentication';\nimport {\n getIntentFromQuote,\n mapIntentOrderStatusToTransactionStatus,\n postSubmitOrder,\n} from '../utils/intent-api';\nimport { signTypedMessage } from '../utils/keyring';\nimport { getNetworkClientIdByChainId } from '../utils/network';\nimport {\n addSyntheticTransaction,\n waitForTxConfirmation,\n} from '../utils/transaction';\nimport { handleEvmApprovals } from './evm-strategy';\nimport { SubmitStrategyParams, SubmitStepResult, SubmitStep } from './types';\n\n/**\n * Submits a synthetic EVM transaction to the TransactionController in order to display the intent order's\n * status in theclients, before the actual transaction is finalized on chain. The resulting transaction\n * is only available locally and is not submitted to the chain.\n *\n * @param orderUid - The order uid of the intent transaction\n * @param args - The parameters for the transaction\n * @returns The tradeMeta for the synthetic transaction\n */\nconst handleSyntheticTx = async (\n orderUid: string,\n args: SubmitStrategyParams,\n) => {\n const {\n quoteResponses: [quoteResponse],\n messenger,\n isBridgeTx,\n selectedAccount,\n } = args;\n const {\n quote: { srcChainId },\n } = quoteResponse;\n\n // Determine transaction type: swap for same-chain, bridge for cross-chain\n const transactionType = isBridgeTx\n ? /* c8 ignore start */\n TransactionType.bridge\n : /* c8 ignore end */\n TransactionType.swap;\n\n const networkClientId = getNetworkClientIdByChainId(messenger, srcChainId);\n\n // This is a synthetic transaction whose purpose is to be able\n // to track the order status via the history\n if (!isEvmTxData(quoteResponse.trade)) {\n throw new Error('Failed to submit intent: trade is not an EVM transaction');\n }\n const intent = getIntentFromQuote(quoteResponse);\n // This is a synthetic transaction whose purpose is to be able\n // to track the order status via the history\n /**\n * @deprecated use trade data from quote response instead\n */\n const intentTransactionParams = {\n chainId: formatChainIdToHex(srcChainId),\n from: selectedAccount.address,\n to:\n intent.settlementContract ?? '0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract\n data: `0x${orderUid?.slice(-8)}`, // Use last 8 chars of orderUid to make each transaction unique\n value: '0x0',\n gas: '0x5208', // Minimal gas for display purposes\n gasPrice: '0x3b9aca00', // 1 Gwei - will be converted to EIP-1559 fees if network supports it\n };\n\n const initialTxMeta = await addSyntheticTransaction(\n messenger,\n intentTransactionParams,\n {\n requireApproval: false,\n networkClientId,\n type: transactionType,\n },\n );\n return initialTxMeta;\n};\n\n/**\n * Submits batched EVM transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @returns The approvalTxId and tradeMeta for the non-EVM transaction\n */\nconst handleSubmitIntent = async (args: SubmitStrategyParams<TxData>) => {\n const {\n quoteResponses: [quoteResponse],\n messenger,\n selectedAccount,\n clientId,\n fetchFn,\n bridgeApiBaseUrl,\n } = args;\n const { srcChainId, requestId } = quoteResponse.quote;\n\n const intent = getIntentFromQuote(quoteResponse);\n const signature = await signTypedMessage({\n messenger,\n accountAddress: selectedAccount.address,\n typedData: intent.typedData,\n });\n\n const { id: orderUid, status } = await postSubmitOrder({\n params: {\n srcChainId,\n quoteId: requestId,\n signature,\n order: intent.order,\n userAddress: selectedAccount.address,\n aggregatorId: intent.protocol,\n },\n clientId,\n jwt: await getJwt(messenger),\n fetchFn,\n bridgeApiBaseUrl,\n });\n\n return {\n orderUid,\n orderStatus: status,\n };\n};\n\n/**\n * Submits an approval tx to the TransactionController,\n * posts an intent order to the bridge-api,\n * and creates a synthetic transaction in the TransactionController\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @yields The approvalTxId and tradeMeta for the intent transaction\n */\nexport async function* submitIntentHandler(\n args: SubmitStrategyParams<TxData>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n // TODO handle STX/batch approvals\n const approvalTxId = await handleEvmApprovals(args);\n approvalTxId && (await waitForTxConfirmation(args.messenger, approvalTxId));\n\n // TODO add to history after approval tx is confirmed\n\n // Submit the intent order to the bridge-api\n const { orderUid, orderStatus } = await handleSubmitIntent(args);\n\n // Initialize a transaction in the TransactionController\n const syntheticTxMeta = await handleSyntheticTx(orderUid, {\n ...args,\n requireApproval: false,\n isStxEnabled: false,\n });\n\n // Use synthetic transaction metadata + translated intent order status as the tradeMeta\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: {\n ...syntheticTxMeta,\n // Map intent order status to TransactionController status\n status: mapIntentOrderStatusToTransactionStatus(orderStatus),\n },\n },\n };\n\n // Update txHistory with synthetic txMeta and order id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n // Use orderId as the history key for intent transactions\n historyKey: orderUid,\n bridgeTxMeta: {\n id: syntheticTxMeta?.id,\n },\n approvalTxId,\n // Keep original txId for TransactionController updates\n originalTransactionId: syntheticTxMeta?.id,\n quoteResponse: args.quoteResponses[0],\n },\n };\n\n // Start polling using the orderId as the history key\n yield {\n type: SubmitStep.StartPolling,\n payload: {\n historyKey: orderUid,\n },\n };\n}\n"]}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.submitNonEvmHandler = void 0;
4
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
5
+ const bridge_controller_1 = require("@metamask/bridge-controller");
6
+ const snaps_1 = require("../utils/snaps.cjs");
7
+ const trace_1 = require("../utils/trace.cjs");
8
+ const transaction_1 = require("../utils/transaction.cjs");
9
+ const types_1 = require("./types.cjs");
10
+ /**
11
+ * Submits the approval transaction for a non-EVM transaction if present
12
+ *
13
+ * @param args - The parameters for the transaction
14
+ * @returns The tx id of the approval transaction
15
+ */
16
+ const handleTronApproval = async (args) => {
17
+ const { quoteResponses: [quoteResponse], traceFn, } = args;
18
+ const approvalTxId = await traceFn((0, trace_1.getApprovalTraceParams)(quoteResponse, false), async () => {
19
+ if (quoteResponse.approval) {
20
+ const txMeta = await (0, snaps_1.handleNonEvmTx)(args.messenger, quoteResponse.approval, quoteResponse, args.selectedAccount);
21
+ return txMeta.id;
22
+ }
23
+ return undefined;
24
+ });
25
+ if (approvalTxId) {
26
+ // Add delay after approval similar to EVM flow
27
+ await (0, transaction_1.handleApprovalDelay)(quoteResponse.quote.srcChainId);
28
+ return approvalTxId;
29
+ }
30
+ return undefined;
31
+ };
32
+ /**
33
+ * Submits Solana, Bitcoin, or Tron transactions to the snap controller
34
+ *
35
+ * @param args - The parameters for the transaction
36
+ * @param args.quoteResponse - The quote response
37
+ * @param args.messenger - The messenger
38
+ * @param args.selectedAccount - The selected account
39
+ * @param args.traceFn - The trace function
40
+ * @param args.isBridgeTx - Whether the transaction is a bridge transaction
41
+ * @yields The approvalTxId and tradeMeta for the non-EVM transaction
42
+ */
43
+ async function* submitNonEvmHandler(args) {
44
+ const { quoteResponses: [quoteResponse], isBridgeTx, } = args;
45
+ const approvalTxId = await handleTronApproval(args);
46
+ // TODO bridge-status should update history with actionId if approvalTxId is present
47
+ const tradeMeta = await (0, snaps_1.handleNonEvmTx)(args.messenger, quoteResponse.trade, quoteResponse, args.selectedAccount);
48
+ yield {
49
+ type: types_1.SubmitStep.SetTradeMeta,
50
+ payload: { tradeMeta },
51
+ };
52
+ yield {
53
+ type: types_1.SubmitStep.AddHistoryItem,
54
+ payload: {
55
+ historyKey: tradeMeta.id,
56
+ approvalTxId,
57
+ bridgeTxMeta: {
58
+ id: tradeMeta.id,
59
+ hash: tradeMeta.hash,
60
+ },
61
+ quoteResponse,
62
+ },
63
+ };
64
+ yield {
65
+ type: types_1.SubmitStep.StartPolling,
66
+ payload: {
67
+ historyKey: tradeMeta.id,
68
+ },
69
+ };
70
+ if (!(0, bridge_controller_1.isTronChainId)(quoteResponse.quote.srcChainId) && !isBridgeTx) {
71
+ yield {
72
+ type: types_1.SubmitStep.PublishCompletedEvent,
73
+ payload: {
74
+ historyKey: tradeMeta.id,
75
+ },
76
+ };
77
+ }
78
+ }
79
+ exports.submitNonEvmHandler = submitNonEvmHandler;
80
+ //# sourceMappingURL=non-evm-strategy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"non-evm-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,mEAA4D;AAO5D,8CAAgD;AAChD,8CAAwD;AACxD,0DAA2D;AAC3D,uCAAqC;AAGrC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,KAAK,EAC9B,IAEC,EACD,EAAE;IACF,MAAM,EACJ,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,OAAO,GACR,GAAG,IAAI,CAAC;IA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I,EAAE,SAAS,CAAC,IAAI;aACrB;YACD,aAAa;SACd;KACF,CAAC;IAEF,MAAM;QACJ,IAAI,EAAE,kBAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,EAAE;SACzB;KACF,CAAC;IAEF,IAAI,CAAC,IAAA,iCAAa,EAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClE,MAAM;YACJ,IAAI,EAAE,kBAAU,CAAC,qBAAqB;YACtC,OAAO,EAAE;gBACP,UAAU,EAAE,SAAS,CAAC,EAAE;aACzB;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAtDD,kDAsDC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { isTronChainId } from '@metamask/bridge-controller';\nimport type {\n BitcoinTradeData,\n TronTradeData,\n TxData,\n} from '@metamask/bridge-controller';\n\nimport { handleNonEvmTx } from '../utils/snaps';\nimport { getApprovalTraceParams } from '../utils/trace';\nimport { handleApprovalDelay } from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\n/**\n * Submits the approval transaction for a non-EVM transaction if present\n *\n * @param args - The parameters for the transaction\n * @returns The tx id of the approval transaction\n */\nconst handleTronApproval = async (\n args: SubmitStrategyParams<\n TronTradeData | BitcoinTradeData | string | TxData\n >,\n) => {\n const {\n quoteResponses: [quoteResponse],\n traceFn,\n } = args;\n\n const approvalTxId = await traceFn(\n getApprovalTraceParams(quoteResponse, false),\n async () => {\n if (quoteResponse.approval) {\n const txMeta = await handleNonEvmTx(\n args.messenger,\n quoteResponse.approval,\n quoteResponse,\n args.selectedAccount,\n );\n return txMeta.id;\n }\n return undefined;\n },\n );\n\n if (approvalTxId) {\n // Add delay after approval similar to EVM flow\n await handleApprovalDelay(quoteResponse.quote.srcChainId);\n return approvalTxId;\n }\n return undefined;\n};\n\n/**\n * Submits Solana, Bitcoin, or Tron transactions to the snap controller\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @yields The approvalTxId and tradeMeta for the non-EVM transaction\n */\nexport async function* submitNonEvmHandler(\n args: SubmitStrategyParams<\n BitcoinTradeData | TronTradeData | string | TxData\n >,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n quoteResponses: [quoteResponse],\n isBridgeTx,\n } = args;\n\n const approvalTxId = await handleTronApproval(args);\n\n // TODO bridge-status should update history with actionId if approvalTxId is present\n\n const tradeMeta = await handleNonEvmTx(\n args.messenger,\n quoteResponse.trade,\n quoteResponse,\n args.selectedAccount,\n );\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: { tradeMeta },\n };\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: tradeMeta.id,\n approvalTxId,\n bridgeTxMeta: {\n id: tradeMeta.id,\n hash: tradeMeta.hash,\n },\n quoteResponse,\n },\n };\n\n yield {\n type: SubmitStep.StartPolling,\n payload: {\n historyKey: tradeMeta.id,\n },\n };\n\n if (!isTronChainId(quoteResponse.quote.srcChainId) && !isBridgeTx) {\n yield {\n type: SubmitStep.PublishCompletedEvent,\n payload: {\n historyKey: tradeMeta.id,\n },\n };\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { BitcoinTradeData, TronTradeData, TxData } from "@metamask/bridge-controller";
2
+ import type { SubmitStrategyParams, SubmitStepResult } from "./types.cjs";
3
+ /**
4
+ * Submits Solana, Bitcoin, or Tron transactions to the snap controller
5
+ *
6
+ * @param args - The parameters for the transaction
7
+ * @param args.quoteResponse - The quote response
8
+ * @param args.messenger - The messenger
9
+ * @param args.selectedAccount - The selected account
10
+ * @param args.traceFn - The trace function
11
+ * @param args.isBridgeTx - Whether the transaction is a bridge transaction
12
+ * @yields The approvalTxId and tradeMeta for the non-EVM transaction
13
+ */
14
+ export declare function submitNonEvmHandler(args: SubmitStrategyParams<BitcoinTradeData | TronTradeData | string | TxData>): AsyncGenerator<SubmitStepResult, void, void>;
15
+ //# sourceMappingURL=non-evm-strategy.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"non-evm-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,MAAM,EACP,oCAAoC;AAMrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AA0CtE;;;;;;;;;;GAUG;AACH,wBAAuB,mBAAmB,CACxC,IAAI,EAAE,oBAAoB,CACxB,gBAAgB,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CACnD,GACA,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAkD9C"}
@@ -0,0 +1,15 @@
1
+ import type { BitcoinTradeData, TronTradeData, TxData } from "@metamask/bridge-controller";
2
+ import type { SubmitStrategyParams, SubmitStepResult } from "./types.mjs";
3
+ /**
4
+ * Submits Solana, Bitcoin, or Tron transactions to the snap controller
5
+ *
6
+ * @param args - The parameters for the transaction
7
+ * @param args.quoteResponse - The quote response
8
+ * @param args.messenger - The messenger
9
+ * @param args.selectedAccount - The selected account
10
+ * @param args.traceFn - The trace function
11
+ * @param args.isBridgeTx - Whether the transaction is a bridge transaction
12
+ * @yields The approvalTxId and tradeMeta for the non-EVM transaction
13
+ */
14
+ export declare function submitNonEvmHandler(args: SubmitStrategyParams<BitcoinTradeData | TronTradeData | string | TxData>): AsyncGenerator<SubmitStepResult, void, void>;
15
+ //# sourceMappingURL=non-evm-strategy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"non-evm-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,MAAM,EACP,oCAAoC;AAMrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AA0CtE;;;;;;;;;;GAUG;AACH,wBAAuB,mBAAmB,CACxC,IAAI,EAAE,oBAAoB,CACxB,gBAAgB,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CACnD,GACA,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CAkD9C"}
@@ -0,0 +1,76 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ import { isTronChainId } from "@metamask/bridge-controller";
3
+ import { handleNonEvmTx } from "../utils/snaps.mjs";
4
+ import { getApprovalTraceParams } from "../utils/trace.mjs";
5
+ import { handleApprovalDelay } from "../utils/transaction.mjs";
6
+ import { SubmitStep } from "./types.mjs";
7
+ /**
8
+ * Submits the approval transaction for a non-EVM transaction if present
9
+ *
10
+ * @param args - The parameters for the transaction
11
+ * @returns The tx id of the approval transaction
12
+ */
13
+ const handleTronApproval = async (args) => {
14
+ const { quoteResponses: [quoteResponse], traceFn, } = args;
15
+ const approvalTxId = await traceFn(getApprovalTraceParams(quoteResponse, false), async () => {
16
+ if (quoteResponse.approval) {
17
+ const txMeta = await handleNonEvmTx(args.messenger, quoteResponse.approval, quoteResponse, args.selectedAccount);
18
+ return txMeta.id;
19
+ }
20
+ return undefined;
21
+ });
22
+ if (approvalTxId) {
23
+ // Add delay after approval similar to EVM flow
24
+ await handleApprovalDelay(quoteResponse.quote.srcChainId);
25
+ return approvalTxId;
26
+ }
27
+ return undefined;
28
+ };
29
+ /**
30
+ * Submits Solana, Bitcoin, or Tron transactions to the snap controller
31
+ *
32
+ * @param args - The parameters for the transaction
33
+ * @param args.quoteResponse - The quote response
34
+ * @param args.messenger - The messenger
35
+ * @param args.selectedAccount - The selected account
36
+ * @param args.traceFn - The trace function
37
+ * @param args.isBridgeTx - Whether the transaction is a bridge transaction
38
+ * @yields The approvalTxId and tradeMeta for the non-EVM transaction
39
+ */
40
+ export async function* submitNonEvmHandler(args) {
41
+ const { quoteResponses: [quoteResponse], isBridgeTx, } = args;
42
+ const approvalTxId = await handleTronApproval(args);
43
+ // TODO bridge-status should update history with actionId if approvalTxId is present
44
+ const tradeMeta = await handleNonEvmTx(args.messenger, quoteResponse.trade, quoteResponse, args.selectedAccount);
45
+ yield {
46
+ type: SubmitStep.SetTradeMeta,
47
+ payload: { tradeMeta },
48
+ };
49
+ yield {
50
+ type: SubmitStep.AddHistoryItem,
51
+ payload: {
52
+ historyKey: tradeMeta.id,
53
+ approvalTxId,
54
+ bridgeTxMeta: {
55
+ id: tradeMeta.id,
56
+ hash: tradeMeta.hash,
57
+ },
58
+ quoteResponse,
59
+ },
60
+ };
61
+ yield {
62
+ type: SubmitStep.StartPolling,
63
+ payload: {
64
+ historyKey: tradeMeta.id,
65
+ },
66
+ };
67
+ if (!isTronChainId(quoteResponse.quote.srcChainId) && !isBridgeTx) {
68
+ yield {
69
+ type: SubmitStep.PublishCompletedEvent,
70
+ payload: {
71
+ historyKey: tradeMeta.id,
72
+ },
73
+ };
74
+ }
75
+ }
76
+ //# sourceMappingURL=non-evm-strategy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"non-evm-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/non-evm-strategy.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,aAAa,EAAE,oCAAoC;AAO5D,OAAO,EAAE,cAAc,EAAE,2BAAuB;AAChD,OAAO,EAAE,sBAAsB,EAAE,2BAAuB;AACxD,OAAO,EAAE,mBAAmB,EAAE,iCAA6B;AAC3D,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAGrC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,KAAK,EAC9B,IAEC,EACD,EAAE;IACF,MAAM,EACJ,cAAc,EAAE,CAAC,aAAa,CAAC,EAC/B,OAAO,GACR,GAAG,IAAI,CAAC;IAET,MAAM,YAAY,GAAG,MAAM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;SACd;KACF,CAAC;IAEF,MAAM;QACJ,IAAI,EAAE,UAAU,CAAC,YAAY;QAC7B,OAAO,EAAE;YACP,UAAU,EAAE,SAAS,CAAC,EAAE;SACzB;KACF,CAAC;IAEF,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClE,MAAM;YACJ,IAAI,EAAE,UAAU,CAAC,qBAAqB;YACtC,OAAO,EAAE;gBACP,UAAU,EAAE,SAAS,CAAC,EAAE;aACzB;SACF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { isTronChainId } from '@metamask/bridge-controller';\nimport type {\n BitcoinTradeData,\n TronTradeData,\n TxData,\n} from '@metamask/bridge-controller';\n\nimport { handleNonEvmTx } from '../utils/snaps';\nimport { getApprovalTraceParams } from '../utils/trace';\nimport { handleApprovalDelay } from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\n/**\n * Submits the approval transaction for a non-EVM transaction if present\n *\n * @param args - The parameters for the transaction\n * @returns The tx id of the approval transaction\n */\nconst handleTronApproval = async (\n args: SubmitStrategyParams<\n TronTradeData | BitcoinTradeData | string | TxData\n >,\n) => {\n const {\n quoteResponses: [quoteResponse],\n traceFn,\n } = args;\n\n const approvalTxId = await traceFn(\n getApprovalTraceParams(quoteResponse, false),\n async () => {\n if (quoteResponse.approval) {\n const txMeta = await handleNonEvmTx(\n args.messenger,\n quoteResponse.approval,\n quoteResponse,\n args.selectedAccount,\n );\n return txMeta.id;\n }\n return undefined;\n },\n );\n\n if (approvalTxId) {\n // Add delay after approval similar to EVM flow\n await handleApprovalDelay(quoteResponse.quote.srcChainId);\n return approvalTxId;\n }\n return undefined;\n};\n\n/**\n * Submits Solana, Bitcoin, or Tron transactions to the snap controller\n *\n * @param args - The parameters for the transaction\n * @param args.quoteResponse - The quote response\n * @param args.messenger - The messenger\n * @param args.selectedAccount - The selected account\n * @param args.traceFn - The trace function\n * @param args.isBridgeTx - Whether the transaction is a bridge transaction\n * @yields The approvalTxId and tradeMeta for the non-EVM transaction\n */\nexport async function* submitNonEvmHandler(\n args: SubmitStrategyParams<\n BitcoinTradeData | TronTradeData | string | TxData\n >,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n quoteResponses: [quoteResponse],\n isBridgeTx,\n } = args;\n\n const approvalTxId = await handleTronApproval(args);\n\n // TODO bridge-status should update history with actionId if approvalTxId is present\n\n const tradeMeta = await handleNonEvmTx(\n args.messenger,\n quoteResponse.trade,\n quoteResponse,\n args.selectedAccount,\n );\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: { tradeMeta },\n };\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: tradeMeta.id,\n approvalTxId,\n bridgeTxMeta: {\n id: tradeMeta.id,\n hash: tradeMeta.hash,\n },\n quoteResponse,\n },\n };\n\n yield {\n type: SubmitStep.StartPolling,\n payload: {\n historyKey: tradeMeta.id,\n },\n };\n\n if (!isTronChainId(quoteResponse.quote.srcChainId) && !isBridgeTx) {\n yield {\n type: SubmitStep.PublishCompletedEvent,\n payload: {\n historyKey: tradeMeta.id,\n },\n };\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubmitStep = void 0;
4
+ var SubmitStep;
5
+ (function (SubmitStep) {
6
+ SubmitStep["AddHistoryItem"] = "addHistoryItem";
7
+ SubmitStep["RekeyHistoryItem"] = "rekeyHistoryItem";
8
+ SubmitStep["StartPolling"] = "startPolling";
9
+ SubmitStep["PublishCompletedEvent"] = "publishCompletedEvent";
10
+ SubmitStep["SetTradeMeta"] = "setTradeMeta";
11
+ SubmitStep["UpdateBatchTransactions"] = "updateBatchTransactions";
12
+ })(SubmitStep || (exports.SubmitStep = SubmitStep = {}));
13
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":";;;AAsBA,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,+CAAiC,CAAA;IACjC,mDAAqC,CAAA;IACrC,2CAA6B,CAAA;IAC7B,6DAA+C,CAAA;IAC/C,2CAA6B,CAAA;IAC7B,iEAAmD,CAAA;AACrD,CAAC,EAPW,UAAU,0BAAV,UAAU,QAOrB","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type {\n BatchSellTradesResponse,\n BridgeClientId,\n QuoteMetadata,\n QuoteResponse,\n Trade,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type {\n BridgeStatusControllerMessenger,\n FetchFunction,\n QuoteAndTxMetadata,\n StartPollingForBridgeTxStatusArgs,\n} from '../types';\n\nexport enum SubmitStep {\n AddHistoryItem = 'addHistoryItem',\n RekeyHistoryItem = 'rekeyHistoryItem',\n StartPolling = 'startPolling',\n PublishCompletedEvent = 'publishCompletedEvent',\n SetTradeMeta = 'setTradeMeta',\n UpdateBatchTransactions = 'updateBatchTransactions',\n}\n\n/**\n * Any possible result returned by steps in a submission strategy. These can be returned in any order.\n */\nexport type SubmitStepResult =\n | {\n type: SubmitStep.AddHistoryItem;\n payload: Pick<\n StartPollingForBridgeTxStatusArgs,\n 'approvalTxId' | 'bridgeTxMeta' | 'originalTransactionId' | 'actionId'\n > & {\n historyKey: string;\n quoteResponse: QuoteResponse & QuoteMetadata;\n batchSellData?: BatchSellTradesResponse;\n quoteIds?: string[];\n };\n }\n | {\n type: SubmitStep.RekeyHistoryItem;\n payload: {\n /** Usually the actionId of the preceeding `approval` transaction */\n oldHistoryKey: string;\n /** Usually the txMeta.id of the `trade` transaction */\n newHistoryKey: string;\n /** The {@link TransactionMeta} for the `trade` transaction after it has been submitted successfully */\n tradeMeta: TransactionMeta;\n };\n }\n | {\n type: SubmitStep.StartPolling;\n payload: {\n /** The `txHistory` key of the transaction to start polling for */\n historyKey: string;\n };\n }\n | {\n type: SubmitStep.PublishCompletedEvent;\n payload: {\n /** The `txHistory` key of the transaction that has been submitted successfully */\n historyKey: string;\n };\n }\n | {\n type: SubmitStep.SetTradeMeta;\n /** The {@link TransactionMeta} for the transaction that has been submitted successfully */\n payload: {\n tradeMeta: TransactionMeta;\n };\n }\n | {\n type: SubmitStep.UpdateBatchTransactions;\n payload: {\n quoteAndTxMetas: QuoteAndTxMetadata[];\n };\n };\n\n/**\n * The parameters for the submission flow\n */\nexport type SubmitStrategyParams<\n TradeType extends Trade = TxData,\n BatchSellTradesResponseType extends\n | BatchSellTradesResponse\n | undefined\n | null = BatchSellTradesResponse | undefined | null,\n> = {\n batchSellTrades: BatchSellTradesResponseType;\n addTransactionBatchFn: TransactionController['addTransactionBatch'];\n isBridgeTx: boolean;\n isDelegatedAccount: boolean;\n isStxEnabled: boolean;\n messenger: BridgeStatusControllerMessenger;\n quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];\n requireApproval: boolean;\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];\n traceFn: TraceCallback;\n // Used for intent transactions\n fetchFn: FetchFunction;\n clientId: BridgeClientId;\n bridgeApiBaseUrl: string;\n};\n"]}
@@ -0,0 +1,77 @@
1
+ import type { AccountsControllerState } from "@metamask/accounts-controller";
2
+ import type { BatchSellTradesResponse, BridgeClientId, QuoteMetadata, QuoteResponse, Trade, TxData } from "@metamask/bridge-controller";
3
+ import type { TraceCallback } from "@metamask/controller-utils";
4
+ import type { TransactionController, TransactionMeta } from "@metamask/transaction-controller";
5
+ import type { BridgeStatusControllerMessenger, FetchFunction, QuoteAndTxMetadata, StartPollingForBridgeTxStatusArgs } from "../types.cjs";
6
+ export declare enum SubmitStep {
7
+ AddHistoryItem = "addHistoryItem",
8
+ RekeyHistoryItem = "rekeyHistoryItem",
9
+ StartPolling = "startPolling",
10
+ PublishCompletedEvent = "publishCompletedEvent",
11
+ SetTradeMeta = "setTradeMeta",
12
+ UpdateBatchTransactions = "updateBatchTransactions"
13
+ }
14
+ /**
15
+ * Any possible result returned by steps in a submission strategy. These can be returned in any order.
16
+ */
17
+ export type SubmitStepResult = {
18
+ type: SubmitStep.AddHistoryItem;
19
+ payload: Pick<StartPollingForBridgeTxStatusArgs, 'approvalTxId' | 'bridgeTxMeta' | 'originalTransactionId' | 'actionId'> & {
20
+ historyKey: string;
21
+ quoteResponse: QuoteResponse & QuoteMetadata;
22
+ batchSellData?: BatchSellTradesResponse;
23
+ quoteIds?: string[];
24
+ };
25
+ } | {
26
+ type: SubmitStep.RekeyHistoryItem;
27
+ payload: {
28
+ /** Usually the actionId of the preceeding `approval` transaction */
29
+ oldHistoryKey: string;
30
+ /** Usually the txMeta.id of the `trade` transaction */
31
+ newHistoryKey: string;
32
+ /** The {@link TransactionMeta} for the `trade` transaction after it has been submitted successfully */
33
+ tradeMeta: TransactionMeta;
34
+ };
35
+ } | {
36
+ type: SubmitStep.StartPolling;
37
+ payload: {
38
+ /** The `txHistory` key of the transaction to start polling for */
39
+ historyKey: string;
40
+ };
41
+ } | {
42
+ type: SubmitStep.PublishCompletedEvent;
43
+ payload: {
44
+ /** The `txHistory` key of the transaction that has been submitted successfully */
45
+ historyKey: string;
46
+ };
47
+ } | {
48
+ type: SubmitStep.SetTradeMeta;
49
+ /** The {@link TransactionMeta} for the transaction that has been submitted successfully */
50
+ payload: {
51
+ tradeMeta: TransactionMeta;
52
+ };
53
+ } | {
54
+ type: SubmitStep.UpdateBatchTransactions;
55
+ payload: {
56
+ quoteAndTxMetas: QuoteAndTxMetadata[];
57
+ };
58
+ };
59
+ /**
60
+ * The parameters for the submission flow
61
+ */
62
+ export type SubmitStrategyParams<TradeType extends Trade = TxData, BatchSellTradesResponseType extends BatchSellTradesResponse | undefined | null = BatchSellTradesResponse | undefined | null> = {
63
+ batchSellTrades: BatchSellTradesResponseType;
64
+ addTransactionBatchFn: TransactionController['addTransactionBatch'];
65
+ isBridgeTx: boolean;
66
+ isDelegatedAccount: boolean;
67
+ isStxEnabled: boolean;
68
+ messenger: BridgeStatusControllerMessenger;
69
+ quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];
70
+ requireApproval: boolean;
71
+ selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];
72
+ traceFn: TraceCallback;
73
+ fetchFn: FetchFunction;
74
+ clientId: BridgeClientId;
75
+ bridgeApiBaseUrl: string;
76
+ };
77
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EACV,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,aAAa,EACb,KAAK,EACL,MAAM,EACP,oCAAoC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAChB,yCAAyC;AAE1C,OAAO,KAAK,EACV,+BAA+B,EAC/B,aAAa,EACb,kBAAkB,EAClB,iCAAiC,EAClC,qBAAiB;AAElB,oBAAY,UAAU;IACpB,cAAc,mBAAmB;IACjC,gBAAgB,qBAAqB;IACrC,YAAY,iBAAiB;IAC7B,qBAAqB,0BAA0B;IAC/C,YAAY,iBAAiB;IAC7B,uBAAuB,4BAA4B;CACpD;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB;IACE,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC;IAChC,OAAO,EAAE,IAAI,CACX,iCAAiC,EACjC,cAAc,GAAG,cAAc,GAAG,uBAAuB,GAAG,UAAU,CACvE,GAAG;QACF,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,EAAE,aAAa,GAAG,aAAa,CA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AAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC;IACxE,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IACjF,OAAO,EAAE,aAAa,CAAC;IAEvB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC"}
@@ -0,0 +1,77 @@
1
+ import type { AccountsControllerState } from "@metamask/accounts-controller";
2
+ import type { BatchSellTradesResponse, BridgeClientId, QuoteMetadata, QuoteResponse, Trade, TxData } from "@metamask/bridge-controller";
3
+ import type { TraceCallback } from "@metamask/controller-utils";
4
+ import type { TransactionController, TransactionMeta } from "@metamask/transaction-controller";
5
+ import type { BridgeStatusControllerMessenger, FetchFunction, QuoteAndTxMetadata, StartPollingForBridgeTxStatusArgs } from "../types.mjs";
6
+ export declare enum SubmitStep {
7
+ AddHistoryItem = "addHistoryItem",
8
+ RekeyHistoryItem = "rekeyHistoryItem",
9
+ StartPolling = "startPolling",
10
+ PublishCompletedEvent = "publishCompletedEvent",
11
+ SetTradeMeta = "setTradeMeta",
12
+ UpdateBatchTransactions = "updateBatchTransactions"
13
+ }
14
+ /**
15
+ * Any possible result returned by steps in a submission strategy. These can be returned in any order.
16
+ */
17
+ export type SubmitStepResult = {
18
+ type: SubmitStep.AddHistoryItem;
19
+ payload: Pick<StartPollingForBridgeTxStatusArgs, 'approvalTxId' | 'bridgeTxMeta' | 'originalTransactionId' | 'actionId'> & {
20
+ historyKey: string;
21
+ quoteResponse: QuoteResponse & QuoteMetadata;
22
+ batchSellData?: BatchSellTradesResponse;
23
+ quoteIds?: string[];
24
+ };
25
+ } | {
26
+ type: SubmitStep.RekeyHistoryItem;
27
+ payload: {
28
+ /** Usually the actionId of the preceeding `approval` transaction */
29
+ oldHistoryKey: string;
30
+ /** Usually the txMeta.id of the `trade` transaction */
31
+ newHistoryKey: string;
32
+ /** The {@link TransactionMeta} for the `trade` transaction after it has been submitted successfully */
33
+ tradeMeta: TransactionMeta;
34
+ };
35
+ } | {
36
+ type: SubmitStep.StartPolling;
37
+ payload: {
38
+ /** The `txHistory` key of the transaction to start polling for */
39
+ historyKey: string;
40
+ };
41
+ } | {
42
+ type: SubmitStep.PublishCompletedEvent;
43
+ payload: {
44
+ /** The `txHistory` key of the transaction that has been submitted successfully */
45
+ historyKey: string;
46
+ };
47
+ } | {
48
+ type: SubmitStep.SetTradeMeta;
49
+ /** The {@link TransactionMeta} for the transaction that has been submitted successfully */
50
+ payload: {
51
+ tradeMeta: TransactionMeta;
52
+ };
53
+ } | {
54
+ type: SubmitStep.UpdateBatchTransactions;
55
+ payload: {
56
+ quoteAndTxMetas: QuoteAndTxMetadata[];
57
+ };
58
+ };
59
+ /**
60
+ * The parameters for the submission flow
61
+ */
62
+ export type SubmitStrategyParams<TradeType extends Trade = TxData, BatchSellTradesResponseType extends BatchSellTradesResponse | undefined | null = BatchSellTradesResponse | undefined | null> = {
63
+ batchSellTrades: BatchSellTradesResponseType;
64
+ addTransactionBatchFn: TransactionController['addTransactionBatch'];
65
+ isBridgeTx: boolean;
66
+ isDelegatedAccount: boolean;
67
+ isStxEnabled: boolean;
68
+ messenger: BridgeStatusControllerMessenger;
69
+ quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];
70
+ requireApproval: boolean;
71
+ selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];
72
+ traceFn: TraceCallback;
73
+ fetchFn: FetchFunction;
74
+ clientId: BridgeClientId;
75
+ bridgeApiBaseUrl: string;
76
+ };
77
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7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,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,GACD;IACE,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC;IAC9B,2FAA2F;IAC3F,OAAO,EAAE;QACP,SAAS,EAAE,eAAe,CAAC;KAC5B,CAAC;CACH,GACD;IACE,IAAI,EAAE,UAAU,CAAC,uBAAuB,CAAC;IACzC,OAAO,EAAE;QACP,eAAe,EAAE,kBAAkB,EAAE,CAAC;KACvC,CAAC;CACH,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAC9B,SAAS,SAAS,KAAK,GAAG,MAAM,EAChC,2BAA2B,SACvB,uBAAuB,GACvB,SAAS,GACT,IAAI,GAAG,uBAAuB,GAAG,SAAS,GAAG,IAAI,IACnD;IACF,eAAe,EAAE,2BAA2B,CAAC;IAC7C,qBAAqB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IACpE,UAAU,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,+BAA+B,CAAC;IAC3C,cAAc,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC;IACxE,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;IACjF,OAAO,EAAE,aAAa,CAAC;IAEvB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC"}
@@ -0,0 +1,10 @@
1
+ export var SubmitStep;
2
+ (function (SubmitStep) {
3
+ SubmitStep["AddHistoryItem"] = "addHistoryItem";
4
+ SubmitStep["RekeyHistoryItem"] = "rekeyHistoryItem";
5
+ SubmitStep["StartPolling"] = "startPolling";
6
+ SubmitStep["PublishCompletedEvent"] = "publishCompletedEvent";
7
+ SubmitStep["SetTradeMeta"] = "setTradeMeta";
8
+ SubmitStep["UpdateBatchTransactions"] = "updateBatchTransactions";
9
+ })(SubmitStep || (SubmitStep = {}));
10
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAN,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,+CAAiC,CAAA;IACjC,mDAAqC,CAAA;IACrC,2CAA6B,CAAA;IAC7B,6DAA+C,CAAA;IAC/C,2CAA6B,CAAA;IAC7B,iEAAmD,CAAA;AACrD,CAAC,EAPW,UAAU,KAAV,UAAU,QAOrB","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type {\n BatchSellTradesResponse,\n BridgeClientId,\n QuoteMetadata,\n QuoteResponse,\n Trade,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { TraceCallback } from '@metamask/controller-utils';\nimport type {\n TransactionController,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type {\n BridgeStatusControllerMessenger,\n FetchFunction,\n QuoteAndTxMetadata,\n StartPollingForBridgeTxStatusArgs,\n} from '../types';\n\nexport enum SubmitStep {\n AddHistoryItem = 'addHistoryItem',\n RekeyHistoryItem = 'rekeyHistoryItem',\n StartPolling = 'startPolling',\n PublishCompletedEvent = 'publishCompletedEvent',\n SetTradeMeta = 'setTradeMeta',\n UpdateBatchTransactions = 'updateBatchTransactions',\n}\n\n/**\n * Any possible result returned by steps in a submission strategy. These can be returned in any order.\n */\nexport type SubmitStepResult =\n | {\n type: SubmitStep.AddHistoryItem;\n payload: Pick<\n StartPollingForBridgeTxStatusArgs,\n 'approvalTxId' | 'bridgeTxMeta' | 'originalTransactionId' | 'actionId'\n > & {\n historyKey: string;\n quoteResponse: QuoteResponse & QuoteMetadata;\n batchSellData?: BatchSellTradesResponse;\n quoteIds?: string[];\n };\n }\n | {\n type: SubmitStep.RekeyHistoryItem;\n payload: {\n /** Usually the actionId of the preceeding `approval` transaction */\n oldHistoryKey: string;\n /** Usually the txMeta.id of the `trade` transaction */\n newHistoryKey: string;\n /** The {@link TransactionMeta} for the `trade` transaction after it has been submitted successfully */\n tradeMeta: TransactionMeta;\n };\n }\n | {\n type: SubmitStep.StartPolling;\n payload: {\n /** The `txHistory` key of the transaction to start polling for */\n historyKey: string;\n };\n }\n | {\n type: SubmitStep.PublishCompletedEvent;\n payload: {\n /** The `txHistory` key of the transaction that has been submitted successfully */\n historyKey: string;\n };\n }\n | {\n type: SubmitStep.SetTradeMeta;\n /** The {@link TransactionMeta} for the transaction that has been submitted successfully */\n payload: {\n tradeMeta: TransactionMeta;\n };\n }\n | {\n type: SubmitStep.UpdateBatchTransactions;\n payload: {\n quoteAndTxMetas: QuoteAndTxMetadata[];\n };\n };\n\n/**\n * The parameters for the submission flow\n */\nexport type SubmitStrategyParams<\n TradeType extends Trade = TxData,\n BatchSellTradesResponseType extends\n | BatchSellTradesResponse\n | undefined\n | null = BatchSellTradesResponse | undefined | null,\n> = {\n batchSellTrades: BatchSellTradesResponseType;\n addTransactionBatchFn: TransactionController['addTransactionBatch'];\n isBridgeTx: boolean;\n isDelegatedAccount: boolean;\n isStxEnabled: boolean;\n messenger: BridgeStatusControllerMessenger;\n quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];\n requireApproval: boolean;\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];\n traceFn: TraceCallback;\n // Used for intent transactions\n fetchFn: FetchFunction;\n clientId: BridgeClientId;\n bridgeApiBaseUrl: string;\n};\n"]}