@metamask/bridge-status-controller 72.0.2 → 72.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -1
- package/dist/bridge-status-controller.cjs +66 -77
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +3 -3
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +3 -3
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +41 -52
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/constants.cjs +8 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +7 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/strategy/batch-sell-strategy.cjs +8 -7
- package/dist/strategy/batch-sell-strategy.cjs.map +1 -1
- package/dist/strategy/batch-sell-strategy.d.cts.map +1 -1
- package/dist/strategy/batch-sell-strategy.d.mts.map +1 -1
- package/dist/strategy/batch-sell-strategy.mjs +8 -7
- package/dist/strategy/batch-sell-strategy.mjs.map +1 -1
- package/dist/strategy/types.cjs +20 -0
- package/dist/strategy/types.cjs.map +1 -1
- package/dist/strategy/types.d.cts +39 -0
- package/dist/strategy/types.d.cts.map +1 -1
- package/dist/strategy/types.d.mts +39 -0
- package/dist/strategy/types.d.mts.map +1 -1
- package/dist/strategy/types.mjs +20 -0
- package/dist/strategy/types.mjs.map +1 -1
- package/dist/utils/bridge.cjs +2 -5
- package/dist/utils/bridge.cjs.map +1 -1
- package/dist/utils/bridge.d.cts +2 -2
- package/dist/utils/bridge.d.cts.map +1 -1
- package/dist/utils/bridge.d.mts +2 -2
- package/dist/utils/bridge.d.mts.map +1 -1
- package/dist/utils/bridge.mjs +3 -6
- package/dist/utils/bridge.mjs.map +1 -1
- package/dist/utils/metrics.cjs +6 -22
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +9 -27
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +9 -27
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +6 -21
- package/dist/utils/metrics.mjs.map +1 -1
- package/package.json +6 -6
package/dist/constants.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAE3D,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,uCAAuC,QAA0B,CAAC;AAE/E,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AAEtE,eAAO,MAAM,sCAAsC,EAAE,2BAGlD,CAAC;AAEJ,eAAO,MAAM,wBAAwB,sCAAsC,CAAC;AAE5E,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,oBAAY,SAAS;IACnB,kCAAkC,0CAA0C;IAC5E,0BAA0B,iCAAiC;IAC3D,gCAAgC,wCAAwC;IACxE,wBAAwB,+BAA+B;CACxD"}
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oCAAoC;AAExD,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAE3D,eAAO,MAAM,mBAAmB,QAAY,CAAC;AAC7C,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,uCAAuC,QAA0B,CAAC;AAE/E,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AAEtE,eAAO,MAAM,sCAAsC,EAAE,2BAGlD,CAAC;AAEJ,eAAO,MAAM,wBAAwB,sCAAsC,CAAC;AAE5E,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,oBAAY,SAAS;IACnB,kCAAkC,0CAA0C;IAC5E,0BAA0B,iCAAiC;IAC3D,gCAAgC,wCAAwC;IACxE,wBAAwB,+BAA+B;CACxD;AAED,eAAO,MAAM,qCAAqC,aAKjD,CAAC"}
|
package/dist/constants.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FeatureId } from "@metamask/bridge-controller";
|
|
1
2
|
export const REFRESH_INTERVAL_MS = 10 * 1000; // 10 seconds
|
|
2
3
|
export const MAX_ATTEMPTS = 7; // at 7 attempts, delay is 10:40, cumulative time is 21:10
|
|
3
4
|
export const DEFAULT_MAX_PENDING_HISTORY_ITEM_AGE_MS = 2 * 24 * 60 * 60 * 1000; // 2 days
|
|
@@ -14,4 +15,10 @@ export var TraceName;
|
|
|
14
15
|
TraceName["SwapTransactionApprovalCompleted"] = "Swap Transaction Approval Completed";
|
|
15
16
|
TraceName["SwapTransactionCompleted"] = "Swap Transaction Completed";
|
|
16
17
|
})(TraceName || (TraceName = {}));
|
|
18
|
+
export const ALLOWED_FEATURE_IDS_FOR_STATUS_EVENTS = [
|
|
19
|
+
FeatureId.QUICK_BUY_FOLLOW_TRADING,
|
|
20
|
+
FeatureId.QUICK_BUY_TOKEN_DETAILS,
|
|
21
|
+
FeatureId.UNIFIED_SWAP_BRIDGE,
|
|
22
|
+
FeatureId.BATCH_SELL,
|
|
23
|
+
];
|
|
17
24
|
//# sourceMappingURL=constants.mjs.map
|
package/dist/constants.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,oCAAoC;AAIxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAC3D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,CAAC,0DAA0D;AACzF,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,SAAS;AAEzF,MAAM,CAAC,MAAM,6BAA6B,GAAG,wBAAwB,CAAC;AAEtE,MAAM,CAAC,MAAM,sCAAsC,GACjD;IACE,SAAS,EAAE,EAAE;CACd,CAAC;AAEJ,MAAM,CAAC,MAAM,wBAAwB,GAAG,mCAAmC,CAAC;AAE5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,yFAA4E,CAAA;IAC5E,wEAA2D,CAAA;IAC3D,qFAAwE,CAAA;IACxE,oEAAuD,CAAA;AACzD,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB;AAED,MAAM,CAAC,MAAM,qCAAqC,GAAG;IACnD,SAAS,CAAC,wBAAwB;IAClC,SAAS,CAAC,uBAAuB;IACjC,SAAS,CAAC,mBAAmB;IAC7B,SAAS,CAAC,UAAU;CACrB,CAAC","sourcesContent":["import { FeatureId } from '@metamask/bridge-controller';\n\nimport type { BridgeStatusControllerState } from './types';\n\nexport const REFRESH_INTERVAL_MS = 10 * 1000; // 10 seconds\nexport const MAX_ATTEMPTS = 7; // at 7 attempts, delay is 10:40, cumulative time is 21:10\nexport const DEFAULT_MAX_PENDING_HISTORY_ITEM_AGE_MS = 2 * 24 * 60 * 60 * 1000; // 2 days\n\nexport const BRIDGE_STATUS_CONTROLLER_NAME = 'BridgeStatusController';\n\nexport const DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE: BridgeStatusControllerState =\n {\n txHistory: {},\n };\n\nexport const BRIDGE_PROD_API_BASE_URL = 'https://bridge.api.cx.metamask.io';\n\nexport const APPROVAL_DELAY_MS = 5000;\n\nexport enum TraceName {\n BridgeTransactionApprovalCompleted = 'Bridge Transaction Approval Completed',\n BridgeTransactionCompleted = 'Bridge Transaction Completed',\n SwapTransactionApprovalCompleted = 'Swap Transaction Approval Completed',\n SwapTransactionCompleted = 'Swap Transaction Completed',\n}\n\nexport const ALLOWED_FEATURE_IDS_FOR_STATUS_EVENTS = [\n FeatureId.QUICK_BUY_FOLLOW_TRADING,\n FeatureId.QUICK_BUY_TOKEN_DETAILS,\n FeatureId.UNIFIED_SWAP_BRIDGE,\n FeatureId.BATCH_SELL,\n];\n"]}
|
|
@@ -12,7 +12,7 @@ const getHistoryKeyForQuote = ({ quoteResponse: { quoteId, quote }, }) => quoteI
|
|
|
12
12
|
* @yields The approvalMeta and tradeMeta for the first batch sell transaction
|
|
13
13
|
*/
|
|
14
14
|
async function* submitBatchSellHandler(args) {
|
|
15
|
-
const { requireApproval, quoteResponses, messenger, addTransactionBatchFn, isDelegatedAccount, batchSellTrades, } = args;
|
|
15
|
+
const { requireApproval, quoteResponses, messenger, addTransactionBatchFn, isDelegatedAccount, batchSellTrades, batchId: batchIdParam, } = args;
|
|
16
16
|
const tradeData = (0, transaction_1.toQuoteAndTxMetadataBatch)({
|
|
17
17
|
quoteResponses,
|
|
18
18
|
batchSellTrades,
|
|
@@ -29,6 +29,7 @@ async function* submitBatchSellHandler(args) {
|
|
|
29
29
|
disable7702: (0, transaction_1.shouldDisable7702)(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
30
30
|
isGasFeeSponsored: gasSponsored,
|
|
31
31
|
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
32
|
+
batchId: batchIdParam,
|
|
32
33
|
skipInitialGasEstimate: gasIncluded7702
|
|
33
34
|
? isDelegatedAccount
|
|
34
35
|
: Boolean(gasFeeToken),
|
|
@@ -49,6 +50,12 @@ async function* submitBatchSellHandler(args) {
|
|
|
49
50
|
if (!firstTradeMeta) {
|
|
50
51
|
throw new Error('Failed to add BatchSell trade to history: txMeta not found');
|
|
51
52
|
}
|
|
53
|
+
yield {
|
|
54
|
+
type: types_1.SubmitStep.SetTradeMeta,
|
|
55
|
+
payload: {
|
|
56
|
+
tradeMeta: firstTradeMeta,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
52
59
|
// Nested/7702 batch
|
|
53
60
|
if ((0, transaction_1.is7702Tx)(firstTradeMeta) || (0, transaction_1.hasNestedSwapTransactions)(firstTradeMeta)) {
|
|
54
61
|
const quoteIds = Array.from(new Set(allTradesInBatch.map(getHistoryKeyForQuote)));
|
|
@@ -92,12 +99,6 @@ async function* submitBatchSellHandler(args) {
|
|
|
92
99
|
};
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
|
-
yield {
|
|
96
|
-
type: types_1.SubmitStep.SetTradeMeta,
|
|
97
|
-
payload: {
|
|
98
|
-
tradeMeta: firstTradeMeta,
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
102
|
}
|
|
102
103
|
exports.submitBatchSellHandler = submitBatchSellHandler;
|
|
103
104
|
//# sourceMappingURL=batch-sell-strategy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":";;;AACA,6EAG0C;AAG1C,0DAQ8B;AAC9B,uCAAqC;AAGrC,MAAM,qBAAqB,GAAG,CAAC,EAC7B,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GACd,EAAU,EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;AAE7D;;;;;GAKG;AACI,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAC3C,IAA2D;IAE3D,MAAM,EACJ,eAAe,EACf,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.cjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":";;;AACA,6EAG0C;AAG1C,0DA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F,mFAAmF;QACnF,KAAK,MAAM,iBAAiB,IAAI,gBAAgB,EAAE,CAAC;YACjD,MAAM,EAAE,aAAa,EAAE,GAAG,iBAAiB,CAAC;YAE5C,MAAM;gBACJ,IAAI,EAAE,kBAAU,CAAC,cAAc;gBAC/B,OAAO,EAAE;oBACP,UAAU,EAAE,qBAAqB,CAAC,iBAAiB,CAAC;oBACpD,aAAa;oBACb,aAAa,EAAE,eAAe;iBAC/B;aACF,CAAC;QACJ,CAAC;IACH,CAAC;SAAM,CAAC;QACN,0DAA0D;QAC1D,6DAA6D;QAC7D,uDAAuD;QACvD,KAAK,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,gBAAgB,EAAE,CAAC;YACzD,MAAM;gBACJ,IAAI,EAAE,kBAAU,CAAC,cAAc;gBAC/B,OAAO,EAAE;oBACP,UAAU,EAAE,MAAM,CAAC,EAAE;oBACrB,aAAa;oBACb,aAAa,EAAE,eAAe;oBAC9B,YAAY,EAAE,MAAM;iBACrB;aACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AA5HD,wDA4HC","sourcesContent":["import { BatchSellTradesResponse, TxData } from '@metamask/bridge-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { QuoteAndTxMetadata } from '../types';\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n hasNestedSwapTransactions,\n is7702Tx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadataBatch,\n} from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\nconst getHistoryKeyForQuote = ({\n quoteResponse: { quoteId, quote },\n}: QuoteAndTxMetadata): string => quoteId ?? quote.requestId;\n\n/**\n * Submits batch-sell transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the first batch sell transaction\n */\nexport async function* submitBatchSellHandler(\n args: SubmitStrategyParams<TxData, BatchSellTradesResponse>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses,\n messenger,\n addTransactionBatchFn,\n isDelegatedAccount,\n batchSellTrades,\n batchId: batchIdParam,\n } = args;\n\n const tradeData = toQuoteAndTxMetadataBatch({\n quoteResponses,\n batchSellTrades,\n });\n\n const { gasIncluded7702, gasIncluded, gasSponsored } = batchSellTrades;\n\n const gasFeeToken = tradeData.find(\n ({ type }) => type === TransactionType.tokenMethodTransfer,\n )?.tx.to;\n\n const transactionParams = await getAddTransactionBatchParams({\n messenger,\n tradeData,\n requireApproval,\n isDelegatedAccount,\n // Tx success/failure is independent of other txs in the batch\n atomic: false,\n disable7702: shouldDisable7702(\n gasIncluded7702,\n gasIncluded,\n isDelegatedAccount,\n ),\n isGasFeeSponsored: gasSponsored,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n batchId: batchIdParam,\n skipInitialGasEstimate: gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !gasFeeToken,\n });\n\n // Submit the batch to the TransactionController\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n // Find all batch transaction metas and add them to history\n const allTradesInBatch = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n }).filter(\n (metadata): metadata is QuoteAndTxMetadata & { txMeta: TransactionMeta } =>\n isTradeTx(metadata.type) && metadata.txMeta !== undefined,\n );\n\n // This is either the delegation tx or the first STX swap in the batch\n const firstTradeWithMetadata = allTradesInBatch.find(\n ({ txMeta }) =>\n txMeta?.type &&\n (isTradeTx(txMeta.type) || hasNestedSwapTransactions(txMeta)),\n );\n const firstTradeMeta = firstTradeWithMetadata?.txMeta;\n if (!firstTradeMeta) {\n throw new Error(\n 'Failed to add BatchSell trade to history: txMeta not found',\n );\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: firstTradeMeta,\n },\n };\n\n // Nested/7702 batch\n if (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta)) {\n const quoteIds = Array.from(\n new Set(allTradesInBatch.map(getHistoryKeyForQuote)),\n );\n\n // Create 1 history item for the parent tx, keyed by the txMeta.id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: firstTradeMeta.id,\n quoteResponse: firstTradeWithMetadata.quoteResponse,\n batchSellData: batchSellTrades,\n quoteIds,\n bridgeTxMeta: firstTradeMeta,\n },\n };\n // Then create a new history item for each nested trade, keyed by quoteId/requestId\n for (const tradeWithMetadata of allTradesInBatch) {\n const { quoteResponse } = tradeWithMetadata;\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: getHistoryKeyForQuote(tradeWithMetadata),\n quoteResponse,\n batchSellData: batchSellTrades,\n },\n };\n }\n } else {\n // Each trade has its own txMeta if not submitted via 7702\n // Create a new history item for each one, keyed by txMeta.id\n // Note that the approvalTxId is not tracked in history\n for (const { txMeta, quoteResponse } of allTradesInBatch) {\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: txMeta.id,\n quoteResponse,\n batchSellData: batchSellTrades,\n bridgeTxMeta: txMeta,\n },\n };\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,oCAAoC;AAiB9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAMtE;;;;;GAKG;AACH,wBAAuB,sBAAsB,CAC3C,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC1D,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.d.cts","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,oCAAoC;AAiB9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAMtE;;;;;GAKG;AACH,wBAAuB,sBAAsB,CAC3C,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC1D,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CA0H9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,oCAAoC;AAiB9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAMtE;;;;;GAKG;AACH,wBAAuB,sBAAsB,CAC3C,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC1D,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.d.mts","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,oCAAoC;AAiB9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,oBAAgB;AAMtE;;;;;GAKG;AACH,wBAAuB,sBAAsB,CAC3C,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAC1D,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,CA0H9C"}
|
|
@@ -9,7 +9,7 @@ const getHistoryKeyForQuote = ({ quoteResponse: { quoteId, quote }, }) => quoteI
|
|
|
9
9
|
* @yields The approvalMeta and tradeMeta for the first batch sell transaction
|
|
10
10
|
*/
|
|
11
11
|
export async function* submitBatchSellHandler(args) {
|
|
12
|
-
const { requireApproval, quoteResponses, messenger, addTransactionBatchFn, isDelegatedAccount, batchSellTrades, } = args;
|
|
12
|
+
const { requireApproval, quoteResponses, messenger, addTransactionBatchFn, isDelegatedAccount, batchSellTrades, batchId: batchIdParam, } = args;
|
|
13
13
|
const tradeData = toQuoteAndTxMetadataBatch({
|
|
14
14
|
quoteResponses,
|
|
15
15
|
batchSellTrades,
|
|
@@ -26,6 +26,7 @@ export async function* submitBatchSellHandler(args) {
|
|
|
26
26
|
disable7702: shouldDisable7702(gasIncluded7702, gasIncluded, isDelegatedAccount),
|
|
27
27
|
isGasFeeSponsored: gasSponsored,
|
|
28
28
|
isGasFeeIncluded: Boolean(gasIncluded7702),
|
|
29
|
+
batchId: batchIdParam,
|
|
29
30
|
skipInitialGasEstimate: gasIncluded7702
|
|
30
31
|
? isDelegatedAccount
|
|
31
32
|
: Boolean(gasFeeToken),
|
|
@@ -46,6 +47,12 @@ export async function* submitBatchSellHandler(args) {
|
|
|
46
47
|
if (!firstTradeMeta) {
|
|
47
48
|
throw new Error('Failed to add BatchSell trade to history: txMeta not found');
|
|
48
49
|
}
|
|
50
|
+
yield {
|
|
51
|
+
type: SubmitStep.SetTradeMeta,
|
|
52
|
+
payload: {
|
|
53
|
+
tradeMeta: firstTradeMeta,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
49
56
|
// Nested/7702 batch
|
|
50
57
|
if (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta)) {
|
|
51
58
|
const quoteIds = Array.from(new Set(allTradesInBatch.map(getHistoryKeyForQuote)));
|
|
@@ -89,11 +96,5 @@ export async function* submitBatchSellHandler(args) {
|
|
|
89
96
|
};
|
|
90
97
|
}
|
|
91
98
|
}
|
|
92
|
-
yield {
|
|
93
|
-
type: SubmitStep.SetTradeMeta,
|
|
94
|
-
payload: {
|
|
95
|
-
tradeMeta: firstTradeMeta,
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
99
|
}
|
|
99
100
|
//# sourceMappingURL=batch-sell-strategy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-sell-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAG1C,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAAyB,EAC1B,iCAA6B;AAC9B,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAGrC,MAAM,qBAAqB,GAAG,CAAC,EAC7B,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GACd,EAAU,EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAC3C,IAA2D;IAE3D,MAAM,EACJ,eAAe,EACf,cAAc,EACd,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,
|
|
1
|
+
{"version":3,"file":"batch-sell-strategy.mjs","sourceRoot":"","sources":["../../src/strategy/batch-sell-strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EAChB,yCAAyC;AAG1C,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,yBAAyB,EAC1B,iCAA6B;AAC9B,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAGrC,MAAM,qBAAqB,GAAG,CAAC,EAC7B,aAAa,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,GACd,EAAU,EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,sBAAsB,CAC3C,IAA2D;IAE3D,MAAM,EACJ,eAAe,EACf,cAAc,EACd,SAAS,EACT,qBA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D;QAC7D,uDAAuD;QACvD,KAAK,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,gBAAgB,EAAE,CAAC;YACzD,MAAM;gBACJ,IAAI,EAAE,UAAU,CAAC,cAAc;gBAC/B,OAAO,EAAE;oBACP,UAAU,EAAE,MAAM,CAAC,EAAE;oBACrB,aAAa;oBACb,aAAa,EAAE,eAAe;oBAC9B,YAAY,EAAE,MAAM;iBACrB;aACF,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { BatchSellTradesResponse, TxData } from '@metamask/bridge-controller';\nimport {\n TransactionMeta,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport { QuoteAndTxMetadata } from '../types';\nimport {\n findAllTransactionsInBatch,\n getAddTransactionBatchParams,\n hasNestedSwapTransactions,\n is7702Tx,\n isTradeTx,\n shouldDisable7702,\n toQuoteAndTxMetadataBatch,\n} from '../utils/transaction';\nimport { SubmitStep } from './types';\nimport type { SubmitStrategyParams, SubmitStepResult } from './types';\n\nconst getHistoryKeyForQuote = ({\n quoteResponse: { quoteId, quote },\n}: QuoteAndTxMetadata): string => quoteId ?? quote.requestId;\n\n/**\n * Submits batch-sell transactions to the TransactionController\n *\n * @param args - The parameters for the transaction\n * @yields The approvalMeta and tradeMeta for the first batch sell transaction\n */\nexport async function* submitBatchSellHandler(\n args: SubmitStrategyParams<TxData, BatchSellTradesResponse>,\n): AsyncGenerator<SubmitStepResult, void, void> {\n const {\n requireApproval,\n quoteResponses,\n messenger,\n addTransactionBatchFn,\n isDelegatedAccount,\n batchSellTrades,\n batchId: batchIdParam,\n } = args;\n\n const tradeData = toQuoteAndTxMetadataBatch({\n quoteResponses,\n batchSellTrades,\n });\n\n const { gasIncluded7702, gasIncluded, gasSponsored } = batchSellTrades;\n\n const gasFeeToken = tradeData.find(\n ({ type }) => type === TransactionType.tokenMethodTransfer,\n )?.tx.to;\n\n const transactionParams = await getAddTransactionBatchParams({\n messenger,\n tradeData,\n requireApproval,\n isDelegatedAccount,\n // Tx success/failure is independent of other txs in the batch\n atomic: false,\n disable7702: shouldDisable7702(\n gasIncluded7702,\n gasIncluded,\n isDelegatedAccount,\n ),\n isGasFeeSponsored: gasSponsored,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n batchId: batchIdParam,\n skipInitialGasEstimate: gasIncluded7702\n ? isDelegatedAccount\n : Boolean(gasFeeToken),\n excludeNativeTokenForFee: !gasFeeToken,\n });\n\n // Submit the batch to the TransactionController\n const { batchId } = await addTransactionBatchFn(transactionParams);\n\n // Find all batch transaction metas and add them to history\n const allTradesInBatch = findAllTransactionsInBatch({\n messenger,\n batchId,\n tradeData,\n }).filter(\n (metadata): metadata is QuoteAndTxMetadata & { txMeta: TransactionMeta } =>\n isTradeTx(metadata.type) && metadata.txMeta !== undefined,\n );\n\n // This is either the delegation tx or the first STX swap in the batch\n const firstTradeWithMetadata = allTradesInBatch.find(\n ({ txMeta }) =>\n txMeta?.type &&\n (isTradeTx(txMeta.type) || hasNestedSwapTransactions(txMeta)),\n );\n const firstTradeMeta = firstTradeWithMetadata?.txMeta;\n if (!firstTradeMeta) {\n throw new Error(\n 'Failed to add BatchSell trade to history: txMeta not found',\n );\n }\n\n yield {\n type: SubmitStep.SetTradeMeta,\n payload: {\n tradeMeta: firstTradeMeta,\n },\n };\n\n // Nested/7702 batch\n if (is7702Tx(firstTradeMeta) || hasNestedSwapTransactions(firstTradeMeta)) {\n const quoteIds = Array.from(\n new Set(allTradesInBatch.map(getHistoryKeyForQuote)),\n );\n\n // Create 1 history item for the parent tx, keyed by the txMeta.id\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: firstTradeMeta.id,\n quoteResponse: firstTradeWithMetadata.quoteResponse,\n batchSellData: batchSellTrades,\n quoteIds,\n bridgeTxMeta: firstTradeMeta,\n },\n };\n // Then create a new history item for each nested trade, keyed by quoteId/requestId\n for (const tradeWithMetadata of allTradesInBatch) {\n const { quoteResponse } = tradeWithMetadata;\n\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: getHistoryKeyForQuote(tradeWithMetadata),\n quoteResponse,\n batchSellData: batchSellTrades,\n },\n };\n }\n } else {\n // Each trade has its own txMeta if not submitted via 7702\n // Create a new history item for each one, keyed by txMeta.id\n // Note that the approvalTxId is not tracked in history\n for (const { txMeta, quoteResponse } of allTradesInBatch) {\n yield {\n type: SubmitStep.AddHistoryItem,\n payload: {\n historyKey: txMeta.id,\n quoteResponse,\n batchSellData: batchSellTrades,\n bridgeTxMeta: txMeta,\n },\n };\n }\n }\n}\n"]}
|
package/dist/strategy/types.cjs
CHANGED
|
@@ -3,11 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SubmitStep = void 0;
|
|
4
4
|
var SubmitStep;
|
|
5
5
|
(function (SubmitStep) {
|
|
6
|
+
/**
|
|
7
|
+
* Adds quote and submission data to BridgeStatusController's `txHistory`
|
|
8
|
+
*/
|
|
6
9
|
SubmitStep["AddHistoryItem"] = "addHistoryItem";
|
|
10
|
+
/**
|
|
11
|
+
* Rekeys the history item keyed by the old history key to the new history key,
|
|
12
|
+
* and merges in the tradeMeta's id and hash
|
|
13
|
+
*/
|
|
7
14
|
SubmitStep["RekeyHistoryItem"] = "rekeyHistoryItem";
|
|
15
|
+
/**
|
|
16
|
+
* Triggers polling for the transaction's status
|
|
17
|
+
*/
|
|
8
18
|
SubmitStep["StartPolling"] = "startPolling";
|
|
19
|
+
/**
|
|
20
|
+
* Publishes the Unified SwapBridge Completed metrics event
|
|
21
|
+
*/
|
|
9
22
|
SubmitStep["PublishCompletedEvent"] = "publishCompletedEvent";
|
|
23
|
+
/**
|
|
24
|
+
* Sets the tradeMeta returned to the client after submission
|
|
25
|
+
*/
|
|
10
26
|
SubmitStep["SetTradeMeta"] = "setTradeMeta";
|
|
27
|
+
/**
|
|
28
|
+
* Updates the transaction type of batch transactions to swap/bridge/swapApproval/bridgeApproval
|
|
29
|
+
* for display purposes.
|
|
30
|
+
*/
|
|
11
31
|
SubmitStep["UpdateBatchTransactions"] = "updateBatchTransactions";
|
|
12
32
|
})(SubmitStep || (exports.SubmitStep = SubmitStep = {}));
|
|
13
33
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":";;;AAuBA,IAAY,UA2BX;AA3BD,WAAY,UAAU;IACpB;;OAEG;IACH,+CAAiC,CAAA;IACjC;;;OAGG;IACH,mDAAqC,CAAA;IACrC;;OAEG;IACH,2CAA6B,CAAA;IAC7B;;OAEG;IACH,6DAA+C,CAAA;IAC/C;;OAEG;IACH,2CAA6B,CAAA;IAC7B;;;OAGG;IACH,iEAAmD,CAAA;AACrD,CAAC,EA3BW,UAAU,0BAAV,UAAU,QA2BrB","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';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n BridgeStatusControllerMessenger,\n FetchFunction,\n QuoteAndTxMetadata,\n StartPollingForBridgeTxStatusArgs,\n} from '../types';\n\nexport enum SubmitStep {\n /**\n * Adds quote and submission data to BridgeStatusController's `txHistory`\n */\n AddHistoryItem = 'addHistoryItem',\n /**\n * Rekeys the history item keyed by the old history key to the new history key,\n * and merges in the tradeMeta's id and hash\n */\n RekeyHistoryItem = 'rekeyHistoryItem',\n /**\n * Triggers polling for the transaction's status\n */\n StartPolling = 'startPolling',\n /**\n * Publishes the Unified SwapBridge Completed metrics event\n */\n PublishCompletedEvent = 'publishCompletedEvent',\n /**\n * Sets the tradeMeta returned to the client after submission\n */\n SetTradeMeta = 'setTradeMeta',\n /**\n * Updates the transaction type of batch transactions to swap/bridge/swapApproval/bridgeApproval\n * for display purposes.\n */\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 /**\n * The response from obtainGaslessBatch API containing submittable transactions and their fees\n */\n batchSellTrades: BatchSellTradesResponseType;\n /**\n * The function to add a transaction batch to the {@link TransactionControllers}\n */\n addTransactionBatchFn: TransactionController['addTransactionBatch'];\n isBridgeTx: boolean;\n isDelegatedAccount: boolean;\n /**\n * Whether the STX is enabled in the wallet. Does not necessarily mean that\n * STX will be used to submit the transaction.\n */\n isStxEnabled: boolean;\n messenger: BridgeStatusControllerMessenger;\n quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];\n /**\n * Set to true so hardware wallets get prompted for approval on mobile\n */\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 * The batch ID of the transaction batch passed to the addTransactionBatchFn\n * This is only used for batch-sell transactions.\n */\n batchId?: Hex;\n};\n"]}
|
|
@@ -2,13 +2,34 @@ import type { AccountsControllerState } from "@metamask/accounts-controller";
|
|
|
2
2
|
import type { BatchSellTradesResponse, BridgeClientId, QuoteMetadata, QuoteResponse, Trade, TxData } from "@metamask/bridge-controller";
|
|
3
3
|
import type { TraceCallback } from "@metamask/controller-utils";
|
|
4
4
|
import type { TransactionController, TransactionMeta } from "@metamask/transaction-controller";
|
|
5
|
+
import type { Hex } from "@metamask/utils";
|
|
5
6
|
import type { BridgeStatusControllerMessenger, FetchFunction, QuoteAndTxMetadata, StartPollingForBridgeTxStatusArgs } from "../types.cjs";
|
|
6
7
|
export declare enum SubmitStep {
|
|
8
|
+
/**
|
|
9
|
+
* Adds quote and submission data to BridgeStatusController's `txHistory`
|
|
10
|
+
*/
|
|
7
11
|
AddHistoryItem = "addHistoryItem",
|
|
12
|
+
/**
|
|
13
|
+
* Rekeys the history item keyed by the old history key to the new history key,
|
|
14
|
+
* and merges in the tradeMeta's id and hash
|
|
15
|
+
*/
|
|
8
16
|
RekeyHistoryItem = "rekeyHistoryItem",
|
|
17
|
+
/**
|
|
18
|
+
* Triggers polling for the transaction's status
|
|
19
|
+
*/
|
|
9
20
|
StartPolling = "startPolling",
|
|
21
|
+
/**
|
|
22
|
+
* Publishes the Unified SwapBridge Completed metrics event
|
|
23
|
+
*/
|
|
10
24
|
PublishCompletedEvent = "publishCompletedEvent",
|
|
25
|
+
/**
|
|
26
|
+
* Sets the tradeMeta returned to the client after submission
|
|
27
|
+
*/
|
|
11
28
|
SetTradeMeta = "setTradeMeta",
|
|
29
|
+
/**
|
|
30
|
+
* Updates the transaction type of batch transactions to swap/bridge/swapApproval/bridgeApproval
|
|
31
|
+
* for display purposes.
|
|
32
|
+
*/
|
|
12
33
|
UpdateBatchTransactions = "updateBatchTransactions"
|
|
13
34
|
}
|
|
14
35
|
/**
|
|
@@ -60,18 +81,36 @@ export type SubmitStepResult = {
|
|
|
60
81
|
* The parameters for the submission flow
|
|
61
82
|
*/
|
|
62
83
|
export type SubmitStrategyParams<TradeType extends Trade = TxData, BatchSellTradesResponseType extends BatchSellTradesResponse | undefined | null = BatchSellTradesResponse | undefined | null> = {
|
|
84
|
+
/**
|
|
85
|
+
* The response from obtainGaslessBatch API containing submittable transactions and their fees
|
|
86
|
+
*/
|
|
63
87
|
batchSellTrades: BatchSellTradesResponseType;
|
|
88
|
+
/**
|
|
89
|
+
* The function to add a transaction batch to the {@link TransactionControllers}
|
|
90
|
+
*/
|
|
64
91
|
addTransactionBatchFn: TransactionController['addTransactionBatch'];
|
|
65
92
|
isBridgeTx: boolean;
|
|
66
93
|
isDelegatedAccount: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Whether the STX is enabled in the wallet. Does not necessarily mean that
|
|
96
|
+
* STX will be used to submit the transaction.
|
|
97
|
+
*/
|
|
67
98
|
isStxEnabled: boolean;
|
|
68
99
|
messenger: BridgeStatusControllerMessenger;
|
|
69
100
|
quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];
|
|
101
|
+
/**
|
|
102
|
+
* Set to true so hardware wallets get prompted for approval on mobile
|
|
103
|
+
*/
|
|
70
104
|
requireApproval: boolean;
|
|
71
105
|
selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];
|
|
72
106
|
traceFn: TraceCallback;
|
|
73
107
|
fetchFn: FetchFunction;
|
|
74
108
|
clientId: BridgeClientId;
|
|
75
109
|
bridgeApiBaseUrl: string;
|
|
110
|
+
/**
|
|
111
|
+
* The batch ID of the transaction batch passed to the addTransactionBatchFn
|
|
112
|
+
* This is only used for batch-sell transactions.
|
|
113
|
+
*/
|
|
114
|
+
batchId?: Hex;
|
|
76
115
|
};
|
|
77
116
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +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;
|
|
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;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,+BAA+B,EAC/B,aAAa,EACb,kBAAkB,EAClB,iCAAiC,EAClC,qBAAiB;AAElB,oBAAY,UAAU;IACpB;;OAEG;IACH,cAAc,mBAAmB;IACjC;;;OAGG;IACH,gBAAgB,qBAAqB;IACr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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;;OAEG;IACH,eAAe,EAAE,2BAA2B,CAAC;IAC7C;;OAEG;IACH,qBAAqB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IACpE,UAAU,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,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;;OAEG;IACH,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;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACf,CAAC"}
|
|
@@ -2,13 +2,34 @@ import type { AccountsControllerState } from "@metamask/accounts-controller";
|
|
|
2
2
|
import type { BatchSellTradesResponse, BridgeClientId, QuoteMetadata, QuoteResponse, Trade, TxData } from "@metamask/bridge-controller";
|
|
3
3
|
import type { TraceCallback } from "@metamask/controller-utils";
|
|
4
4
|
import type { TransactionController, TransactionMeta } from "@metamask/transaction-controller";
|
|
5
|
+
import type { Hex } from "@metamask/utils";
|
|
5
6
|
import type { BridgeStatusControllerMessenger, FetchFunction, QuoteAndTxMetadata, StartPollingForBridgeTxStatusArgs } from "../types.mjs";
|
|
6
7
|
export declare enum SubmitStep {
|
|
8
|
+
/**
|
|
9
|
+
* Adds quote and submission data to BridgeStatusController's `txHistory`
|
|
10
|
+
*/
|
|
7
11
|
AddHistoryItem = "addHistoryItem",
|
|
12
|
+
/**
|
|
13
|
+
* Rekeys the history item keyed by the old history key to the new history key,
|
|
14
|
+
* and merges in the tradeMeta's id and hash
|
|
15
|
+
*/
|
|
8
16
|
RekeyHistoryItem = "rekeyHistoryItem",
|
|
17
|
+
/**
|
|
18
|
+
* Triggers polling for the transaction's status
|
|
19
|
+
*/
|
|
9
20
|
StartPolling = "startPolling",
|
|
21
|
+
/**
|
|
22
|
+
* Publishes the Unified SwapBridge Completed metrics event
|
|
23
|
+
*/
|
|
10
24
|
PublishCompletedEvent = "publishCompletedEvent",
|
|
25
|
+
/**
|
|
26
|
+
* Sets the tradeMeta returned to the client after submission
|
|
27
|
+
*/
|
|
11
28
|
SetTradeMeta = "setTradeMeta",
|
|
29
|
+
/**
|
|
30
|
+
* Updates the transaction type of batch transactions to swap/bridge/swapApproval/bridgeApproval
|
|
31
|
+
* for display purposes.
|
|
32
|
+
*/
|
|
12
33
|
UpdateBatchTransactions = "updateBatchTransactions"
|
|
13
34
|
}
|
|
14
35
|
/**
|
|
@@ -60,18 +81,36 @@ export type SubmitStepResult = {
|
|
|
60
81
|
* The parameters for the submission flow
|
|
61
82
|
*/
|
|
62
83
|
export type SubmitStrategyParams<TradeType extends Trade = TxData, BatchSellTradesResponseType extends BatchSellTradesResponse | undefined | null = BatchSellTradesResponse | undefined | null> = {
|
|
84
|
+
/**
|
|
85
|
+
* The response from obtainGaslessBatch API containing submittable transactions and their fees
|
|
86
|
+
*/
|
|
63
87
|
batchSellTrades: BatchSellTradesResponseType;
|
|
88
|
+
/**
|
|
89
|
+
* The function to add a transaction batch to the {@link TransactionControllers}
|
|
90
|
+
*/
|
|
64
91
|
addTransactionBatchFn: TransactionController['addTransactionBatch'];
|
|
65
92
|
isBridgeTx: boolean;
|
|
66
93
|
isDelegatedAccount: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Whether the STX is enabled in the wallet. Does not necessarily mean that
|
|
96
|
+
* STX will be used to submit the transaction.
|
|
97
|
+
*/
|
|
67
98
|
isStxEnabled: boolean;
|
|
68
99
|
messenger: BridgeStatusControllerMessenger;
|
|
69
100
|
quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];
|
|
101
|
+
/**
|
|
102
|
+
* Set to true so hardware wallets get prompted for approval on mobile
|
|
103
|
+
*/
|
|
70
104
|
requireApproval: boolean;
|
|
71
105
|
selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string];
|
|
72
106
|
traceFn: TraceCallback;
|
|
73
107
|
fetchFn: FetchFunction;
|
|
74
108
|
clientId: BridgeClientId;
|
|
75
109
|
bridgeApiBaseUrl: string;
|
|
110
|
+
/**
|
|
111
|
+
* The batch ID of the transaction batch passed to the addTransactionBatchFn
|
|
112
|
+
* This is only used for batch-sell transactions.
|
|
113
|
+
*/
|
|
114
|
+
batchId?: Hex;
|
|
76
115
|
};
|
|
77
116
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","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;
|
|
1
|
+
{"version":3,"file":"types.d.mts","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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function (SubmitStep) {
|
|
3
|
+
/**
|
|
4
|
+
* Adds quote and submission data to BridgeStatusController's `txHistory`
|
|
5
|
+
*/
|
|
3
6
|
SubmitStep["AddHistoryItem"] = "addHistoryItem";
|
|
7
|
+
/**
|
|
8
|
+
* Rekeys the history item keyed by the old history key to the new history key,
|
|
9
|
+
* and merges in the tradeMeta's id and hash
|
|
10
|
+
*/
|
|
4
11
|
SubmitStep["RekeyHistoryItem"] = "rekeyHistoryItem";
|
|
12
|
+
/**
|
|
13
|
+
* Triggers polling for the transaction's status
|
|
14
|
+
*/
|
|
5
15
|
SubmitStep["StartPolling"] = "startPolling";
|
|
16
|
+
/**
|
|
17
|
+
* Publishes the Unified SwapBridge Completed metrics event
|
|
18
|
+
*/
|
|
6
19
|
SubmitStep["PublishCompletedEvent"] = "publishCompletedEvent";
|
|
20
|
+
/**
|
|
21
|
+
* Sets the tradeMeta returned to the client after submission
|
|
22
|
+
*/
|
|
7
23
|
SubmitStep["SetTradeMeta"] = "setTradeMeta";
|
|
24
|
+
/**
|
|
25
|
+
* Updates the transaction type of batch transactions to swap/bridge/swapApproval/bridgeApproval
|
|
26
|
+
* for display purposes.
|
|
27
|
+
*/
|
|
8
28
|
SubmitStep["UpdateBatchTransactions"] = "updateBatchTransactions";
|
|
9
29
|
})(SubmitStep || (SubmitStep = {}));
|
|
10
30
|
//# sourceMappingURL=types.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/strategy/types.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAN,IAAY,UA2BX;AA3BD,WAAY,UAAU;IACpB;;OAEG;IACH,+CAAiC,CAAA;IACjC;;;OAGG;IACH,mDAAqC,CAAA;IACrC;;OAEG;IACH,2CAA6B,CAAA;IAC7B;;OAEG;IACH,6DAA+C,CAAA;IAC/C;;OAEG;IACH,2CAA6B,CAAA;IAC7B;;;OAGG;IACH,iEAAmD,CAAA;AACrD,CAAC,EA3BW,UAAU,KAAV,UAAU,QA2BrB","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';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n BridgeStatusControllerMessenger,\n FetchFunction,\n QuoteAndTxMetadata,\n StartPollingForBridgeTxStatusArgs,\n} from '../types';\n\nexport enum SubmitStep {\n /**\n * Adds quote and submission data to BridgeStatusController's `txHistory`\n */\n AddHistoryItem = 'addHistoryItem',\n /**\n * Rekeys the history item keyed by the old history key to the new history key,\n * and merges in the tradeMeta's id and hash\n */\n RekeyHistoryItem = 'rekeyHistoryItem',\n /**\n * Triggers polling for the transaction's status\n */\n StartPolling = 'startPolling',\n /**\n * Publishes the Unified SwapBridge Completed metrics event\n */\n PublishCompletedEvent = 'publishCompletedEvent',\n /**\n * Sets the tradeMeta returned to the client after submission\n */\n SetTradeMeta = 'setTradeMeta',\n /**\n * Updates the transaction type of batch transactions to swap/bridge/swapApproval/bridgeApproval\n * for display purposes.\n */\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 /**\n * The response from obtainGaslessBatch API containing submittable transactions and their fees\n */\n batchSellTrades: BatchSellTradesResponseType;\n /**\n * The function to add a transaction batch to the {@link TransactionControllers}\n */\n addTransactionBatchFn: TransactionController['addTransactionBatch'];\n isBridgeTx: boolean;\n isDelegatedAccount: boolean;\n /**\n * Whether the STX is enabled in the wallet. Does not necessarily mean that\n * STX will be used to submit the transaction.\n */\n isStxEnabled: boolean;\n messenger: BridgeStatusControllerMessenger;\n quoteResponses: (QuoteResponse<TradeType, TradeType> & QuoteMetadata)[];\n /**\n * Set to true so hardware wallets get prompted for approval on mobile\n */\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 * The batch ID of the transaction batch passed to the addTransactionBatchFn\n * This is only used for batch-sell transactions.\n */\n batchId?: Hex;\n};\n"]}
|
package/dist/utils/bridge.cjs
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.trackMetricsEvent = exports.getBatchSellTrades = exports.stopPollingForQuotes = void 0;
|
|
4
4
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
5
|
-
const stopPollingForQuotes = (messenger,
|
|
6
|
-
messenger.call('BridgeController:stopPollingForQuotes', bridge_controller_1.AbortReason.TransactionSubmitted,
|
|
7
|
-
// If trade is submitted before all quotes are loaded, the QuotesReceived event is published
|
|
8
|
-
// If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
|
|
9
|
-
featureId ? undefined : metricsContext);
|
|
5
|
+
const stopPollingForQuotes = (messenger, metricsContext) => {
|
|
6
|
+
messenger.call('BridgeController:stopPollingForQuotes', bridge_controller_1.AbortReason.TransactionSubmitted, metricsContext);
|
|
10
7
|
};
|
|
11
8
|
exports.stopPollingForQuotes = stopPollingForQuotes;
|
|
12
9
|
const getBatchSellTrades = (messenger) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,mEAKqC;AAI9B,MAAM,oBAAoB,GAAG,CAClC,SAA0C,EAC1C,cAA0F,EACpF,EAAE;IACR,SAAS,CAAC,IAAI,CACZ,uCAAuC,EACvC,+BAAW,CAAC,oBAAoB,EAChC,cAAc,CACf,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B;AAEK,MAAM,kBAAkB,GAAG,CAChC,SAA0C,EACV,EAAE;IAClC,OAAO,SAAS,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,eAAe,CAAC;AACrE,CAAC,CAAC;AAJW,QAAA,kBAAkB,sBAI7B;AAEK,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,GAKX,EAAQ,EAAE;IACT,SAAS,CAAC,IAAI,CACZ,8CAA8C,EAC9C,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B","sourcesContent":["import {\n AbortReason,\n UnifiedSwapBridgeEventName,\n BatchSellTradesResponse,\n RequiredEventContextFromClient,\n} from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const stopPollingForQuotes = (\n messenger: BridgeStatusControllerMessenger,\n metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n): void => {\n messenger.call(\n 'BridgeController:stopPollingForQuotes',\n AbortReason.TransactionSubmitted,\n metricsContext,\n );\n};\n\nexport const getBatchSellTrades = (\n messenger: BridgeStatusControllerMessenger,\n): BatchSellTradesResponse | null => {\n return messenger.call('BridgeController:getState').batchSellTrades;\n};\n\nexport const trackMetricsEvent = ({\n messenger,\n eventName,\n properties,\n}: {\n messenger: BridgeStatusControllerMessenger;\n eventName: UnifiedSwapBridgeEventName;\n properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];\n}): void => {\n messenger.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n properties,\n );\n};\n"]}
|
package/dist/utils/bridge.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnifiedSwapBridgeEventName, BatchSellTradesResponse, RequiredEventContextFromClient } from "@metamask/bridge-controller";
|
|
2
2
|
import { BridgeStatusControllerMessenger } from "../types.cjs";
|
|
3
|
-
export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger,
|
|
3
|
+
export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger, metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived]) => void;
|
|
4
4
|
export declare const getBatchSellTrades: (messenger: BridgeStatusControllerMessenger) => BatchSellTradesResponse | null;
|
|
5
5
|
export declare const trackMetricsEvent: ({ messenger, eventName, properties, }: {
|
|
6
6
|
messenger: BridgeStatusControllerMessenger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,uBAAuB,EACvB,8BAA8B,EAC/B,oCAAoC;AAErC,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,oBAAoB,gEAEd,8BAA8B,CAAC,2BAA2B,cAAc,CAAC,KACzF,IAMF,CAAC;AAEF,eAAO,MAAM,kBAAkB,kDAE5B,uBAAuB,GAAG,IAE5B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;eAMjB,0BAA0B;gBACzB,8BAA8B,CAAC,0BAA0B,CAAC;MACpE,IAMH,CAAC"}
|
package/dist/utils/bridge.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnifiedSwapBridgeEventName, BatchSellTradesResponse, RequiredEventContextFromClient } from "@metamask/bridge-controller";
|
|
2
2
|
import { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
3
|
-
export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger,
|
|
3
|
+
export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger, metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived]) => void;
|
|
4
4
|
export declare const getBatchSellTrades: (messenger: BridgeStatusControllerMessenger) => BatchSellTradesResponse | null;
|
|
5
5
|
export declare const trackMetricsEvent: ({ messenger, eventName, properties, }: {
|
|
6
6
|
messenger: BridgeStatusControllerMessenger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,uBAAuB,EACvB,8BAA8B,EAC/B,oCAAoC;AAErC,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,oBAAoB,gEAEd,8BAA8B,CAAC,2BAA2B,cAAc,CAAC,KACzF,IAMF,CAAC;AAEF,eAAO,MAAM,kBAAkB,kDAE5B,uBAAuB,GAAG,IAE5B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;eAMjB,0BAA0B;gBACzB,8BAA8B,CAAC,0BAA0B,CAAC;MACpE,IAMH,CAAC"}
|
package/dist/utils/bridge.mjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { AbortReason,
|
|
2
|
-
export const stopPollingForQuotes = (messenger,
|
|
3
|
-
messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted,
|
|
4
|
-
// If trade is submitted before all quotes are loaded, the QuotesReceived event is published
|
|
5
|
-
// If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
|
|
6
|
-
featureId ? undefined : metricsContext);
|
|
1
|
+
import { AbortReason, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
|
|
2
|
+
export const stopPollingForQuotes = (messenger, metricsContext) => {
|
|
3
|
+
messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted, metricsContext);
|
|
7
4
|
};
|
|
8
5
|
export const getBatchSellTrades = (messenger) => {
|
|
9
6
|
return messenger.call('BridgeController:getState').batchSellTrades;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.mjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,
|
|
1
|
+
{"version":3,"file":"bridge.mjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,0BAA0B,EAG3B,oCAAoC;AAIrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,SAA0C,EAC1C,cAA0F,EACpF,EAAE;IACR,SAAS,CAAC,IAAI,CACZ,uCAAuC,EACvC,WAAW,CAAC,oBAAoB,EAChC,cAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAA0C,EACV,EAAE;IAClC,OAAO,SAAS,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,eAAe,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,GAKX,EAAQ,EAAE;IACT,SAAS,CAAC,IAAI,CACZ,8CAA8C,EAC9C,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n AbortReason,\n UnifiedSwapBridgeEventName,\n BatchSellTradesResponse,\n RequiredEventContextFromClient,\n} from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const stopPollingForQuotes = (\n messenger: BridgeStatusControllerMessenger,\n metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n): void => {\n messenger.call(\n 'BridgeController:stopPollingForQuotes',\n AbortReason.TransactionSubmitted,\n metricsContext,\n );\n};\n\nexport const getBatchSellTrades = (\n messenger: BridgeStatusControllerMessenger,\n): BatchSellTradesResponse | null => {\n return messenger.call('BridgeController:getState').batchSellTrades;\n};\n\nexport const trackMetricsEvent = ({\n messenger,\n eventName,\n properties,\n}: {\n messenger: BridgeStatusControllerMessenger;\n eventName: UnifiedSwapBridgeEventName;\n properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];\n}): void => {\n messenger.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n properties,\n );\n};\n"]}
|