@metamask-previews/bridge-status-controller 12.0.1-preview-eeefabb3 → 12.0.1-preview-1b8ef4d5
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 +11 -0
- package/dist/bridge-status-controller.cjs +267 -6
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +25 -4
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +25 -4
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.mjs +269 -8
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/constants.cjs +3 -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 +2 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +10 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +27 -7
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +27 -7
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +9 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge-status.cjs +6 -5
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +6 -5
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/gas.cjs +31 -0
- package/dist/utils/gas.cjs.map +1 -0
- package/dist/utils/gas.d.cts +20 -0
- package/dist/utils/gas.d.cts.map +1 -0
- package/dist/utils/gas.d.mts +20 -0
- package/dist/utils/gas.d.mts.map +1 -0
- package/dist/utils/gas.mjs +27 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/smart-transactions.cjs +21 -0
- package/dist/utils/smart-transactions.cjs.map +1 -0
- package/dist/utils/smart-transactions.d.cts +12 -0
- package/dist/utils/smart-transactions.d.cts.map +1 -0
- package/dist/utils/smart-transactions.d.mts +12 -0
- package/dist/utils/smart-transactions.d.mts.map +1 -0
- package/dist/utils/smart-transactions.mjs +17 -0
- package/dist/utils/smart-transactions.mjs.map +1 -0
- package/dist/utils/transaction.cjs +115 -0
- package/dist/utils/transaction.cjs.map +1 -0
- package/dist/utils/transaction.d.cts +45 -0
- package/dist/utils/transaction.d.cts.map +1 -0
- package/dist/utils/transaction.d.mts +45 -0
- package/dist/utils/transaction.d.mts.map +1 -0
- package/dist/utils/transaction.mjs +106 -0
- package/dist/utils/transaction.mjs.map +1 -0
- package/dist/utils/validators.cjs +1 -1
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.mjs +2 -2
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +19 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"bridge-status.mjs","sourceRoot":"","sources":["../../src/utils/bridge-status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAE,yBAAqB;AAQ5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,CAAC;IACtD,aAAa,EAAE,QAAQ;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,gBAAwB,EAAE,EAAE,CAC7D,GAAG,gBAAgB,cAAc,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,aAAyC,EACvB,EAAE;IACpB,MAAM,EAAE,KAAK,EAAE,GAAG,oBAAoB,EAAE,GAAG,aAAa,CAAC;IAEzD,M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,CAAC,CAAC;IAEH,WAAW;IACX,4BAA4B,CAAC,WAAW,CAAC,CAAC;IAE1C,SAAS;IACT,OAAO,WAA6B,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,KAAY,EACZ,SAAiB,EACW,EAAE;IAC9B,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACrE,OAAO;QACL,QAAQ;QACR,SAAS;QACT,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAClB,UAAU;QACV,WAAW;QACX,KAAK;QACL,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;KACxB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Quote } from '@metamask/bridge-controller';\n\nimport { validateBridgeStatusResponse } from './validators';\nimport type {\n StatusResponse,\n StatusRequestWithSrcTxHash,\n StatusRequestDto,\n FetchFunction,\n} from '../types';\n\nexport const getClientIdHeader = (clientId: string) => ({\n 'X-Client-Id': clientId,\n});\n\nexport const getBridgeStatusUrl = (bridgeApiBaseUrl: string) =>\n `${bridgeApiBaseUrl}/getTxStatus`;\n\nexport const getStatusRequestDto = (\n statusRequest: StatusRequestWithSrcTxHash,\n): StatusRequestDto => {\n const { quote, ...statusRequestNoQuote } = statusRequest;\n\n const statusRequestNoQuoteFormatted = Object.fromEntries(\n Object.entries(statusRequestNoQuote).map(([key, value]) => [\n key,\n value.toString(),\n ]),\n ) as unknown as Omit<StatusRequestDto, 'requestId'>;\n\n const requestId: { requestId: string } | Record<string, never> =\n quote?.requestId ? { requestId: quote.requestId } : {};\n\n return {\n ...statusRequestNoQuoteFormatted,\n ...requestId,\n };\n};\n\nexport const fetchBridgeTxStatus = async (\n statusRequest: StatusRequestWithSrcTxHash,\n clientId: string,\n fetchFn: FetchFunction,\n bridgeApiBaseUrl: string,\n): Promise<StatusResponse> => {\n const statusRequestDto = getStatusRequestDto(statusRequest);\n const params = new URLSearchParams(statusRequestDto);\n\n // Fetch\n const url = `${getBridgeStatusUrl(bridgeApiBaseUrl)}?${params.toString()}`;\n\n const rawTxStatus: unknown = await fetchFn(url, {\n headers: getClientIdHeader(clientId),\n });\n\n // Validate\n validateBridgeStatusResponse(rawTxStatus);\n\n // Return\n return rawTxStatus as StatusResponse;\n};\n\nexport const getStatusRequestWithSrcTxHash = (\n quote: Quote,\n srcTxHash: string,\n): StatusRequestWithSrcTxHash => {\n const { bridgeId, bridges, srcChainId, destChainId, refuel } = quote;\n return {\n bridgeId,\n srcTxHash,\n bridge: bridges[0],\n srcChainId,\n destChainId,\n quote,\n refuel: Boolean(refuel),\n };\n};\n"]}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getTxGasEstimates = void 0;
|
4
|
+
const bignumber_js_1 = require("bignumber.js");
|
5
|
+
const getTransaction1559GasFeeEstimates = (txGasFeeEstimates, estimatedBaseFee) => {
|
6
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};
|
7
|
+
const baseAndPriorityFeePerGas = maxPriorityFeePerGas
|
8
|
+
? new bignumber_js_1.BigNumber(estimatedBaseFee, 10)
|
9
|
+
.times(10 ** 9)
|
10
|
+
.plus(maxPriorityFeePerGas, 16)
|
11
|
+
: undefined;
|
12
|
+
return {
|
13
|
+
baseAndPriorityFeePerGas,
|
14
|
+
maxFeePerGas,
|
15
|
+
maxPriorityFeePerGas,
|
16
|
+
};
|
17
|
+
};
|
18
|
+
/**
|
19
|
+
* Get the gas fee estimates for a transaction
|
20
|
+
*
|
21
|
+
* @param params - The parameters for the gas fee estimates
|
22
|
+
* @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
|
23
|
+
* @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
|
24
|
+
* @returns The gas fee estimates for the transaction
|
25
|
+
*/
|
26
|
+
const getTxGasEstimates = ({ txGasFeeEstimates, networkGasFeeEstimates, }) => {
|
27
|
+
const { estimatedBaseFee = '0' } = networkGasFeeEstimates;
|
28
|
+
return getTransaction1559GasFeeEstimates(txGasFeeEstimates, estimatedBaseFee);
|
29
|
+
};
|
30
|
+
exports.getTxGasEstimates = getTxGasEstimates;
|
31
|
+
//# sourceMappingURL=gas.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AAQA,+CAAyC;AAEzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAAG,iBAAiB,EAAE,IAAI,IAAI,EAAE,CAAC;IAE7E,MAAM,wBAAwB,GAAG,oBAAoB;QACnD,CAAC,CAAC,IAAI,wBAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;aAChC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aACd,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC;QACnC,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,wBAAwB;QACxB,YAAY;QACZ,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,CAAC,EAChC,iBAAiB,EACjB,sBAAsB,GAMvB,EAAE,EAAE;IACH,MAAM,EAAE,gBAAgB,GAAG,GAAG,EAAE,GAAG,sBAAyC,CAAC;IAC7E,OAAO,iCAAiC,CACtC,iBAAwD,EACxD,gBAAgB,CACjB,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B","sourcesContent":["import type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n"]}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
2
|
+
import type { TransactionController } from "@metamask/transaction-controller";
|
3
|
+
import { BigNumber } from "bignumber.js";
|
4
|
+
/**
|
5
|
+
* Get the gas fee estimates for a transaction
|
6
|
+
*
|
7
|
+
* @param params - The parameters for the gas fee estimates
|
8
|
+
* @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
|
9
|
+
* @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
|
10
|
+
* @returns The gas fee estimates for the transaction
|
11
|
+
*/
|
12
|
+
export declare const getTxGasEstimates: ({ txGasFeeEstimates, networkGasFeeEstimates, }: {
|
13
|
+
txGasFeeEstimates: Awaited<ReturnType<TransactionController['estimateGasFee']>>['estimates'];
|
14
|
+
networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];
|
15
|
+
}) => {
|
16
|
+
baseAndPriorityFeePerGas: BigNumber | undefined;
|
17
|
+
maxFeePerGas: `0x${string}`;
|
18
|
+
maxPriorityFeePerGas: `0x${string}`;
|
19
|
+
};
|
20
|
+
//# sourceMappingURL=gas.d.cts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAqBzC;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
2
|
+
import type { TransactionController } from "@metamask/transaction-controller";
|
3
|
+
import { BigNumber } from "bignumber.js";
|
4
|
+
/**
|
5
|
+
* Get the gas fee estimates for a transaction
|
6
|
+
*
|
7
|
+
* @param params - The parameters for the gas fee estimates
|
8
|
+
* @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
|
9
|
+
* @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
|
10
|
+
* @returns The gas fee estimates for the transaction
|
11
|
+
*/
|
12
|
+
export declare const getTxGasEstimates: ({ txGasFeeEstimates, networkGasFeeEstimates, }: {
|
13
|
+
txGasFeeEstimates: Awaited<ReturnType<TransactionController['estimateGasFee']>>['estimates'];
|
14
|
+
networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];
|
15
|
+
}) => {
|
16
|
+
baseAndPriorityFeePerGas: BigNumber | undefined;
|
17
|
+
maxFeePerGas: `0x${string}`;
|
18
|
+
maxPriorityFeePerGas: `0x${string}`;
|
19
|
+
};
|
20
|
+
//# sourceMappingURL=gas.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACZ,qCAAqC;AACtC,OAAO,KAAK,EAEV,qBAAqB,EACtB,yCAAyC;AAC1C,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAqBzC;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;uBAIT,QACjB,WAAW,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CACpD,CAAC,WAAW,CAAC;4BACU,WAAW,CAAC,iBAAiB,CAAC;;;;;CAOvD,CAAC"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
2
|
+
const getTransaction1559GasFeeEstimates = (txGasFeeEstimates, estimatedBaseFee) => {
|
3
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};
|
4
|
+
const baseAndPriorityFeePerGas = maxPriorityFeePerGas
|
5
|
+
? new BigNumber(estimatedBaseFee, 10)
|
6
|
+
.times(10 ** 9)
|
7
|
+
.plus(maxPriorityFeePerGas, 16)
|
8
|
+
: undefined;
|
9
|
+
return {
|
10
|
+
baseAndPriorityFeePerGas,
|
11
|
+
maxFeePerGas,
|
12
|
+
maxPriorityFeePerGas,
|
13
|
+
};
|
14
|
+
};
|
15
|
+
/**
|
16
|
+
* Get the gas fee estimates for a transaction
|
17
|
+
*
|
18
|
+
* @param params - The parameters for the gas fee estimates
|
19
|
+
* @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)
|
20
|
+
* @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)
|
21
|
+
* @returns The gas fee estimates for the transaction
|
22
|
+
*/
|
23
|
+
export const getTxGasEstimates = ({ txGasFeeEstimates, networkGasFeeEstimates, }) => {
|
24
|
+
const { estimatedBaseFee = '0' } = networkGasFeeEstimates;
|
25
|
+
return getTransaction1559GasFeeEstimates(txGasFeeEstimates, estimatedBaseFee);
|
26
|
+
};
|
27
|
+
//# sourceMappingURL=gas.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,MAAM,iCAAiC,GAAG,CACxC,iBAA2C,EAC3C,gBAAwB,EACxB,EAAE;IACF,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAAG,iBAAiB,EAAE,IAAI,IAAI,EAAE,CAAC;IAE7E,MAAM,wBAAwB,GAAG,oBAAoB;QACnD,CAAC,CAAC,IAAI,SAAS,CAAC,gBAAgB,EAAE,EAAE,CAAC;aAChC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aACd,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAC;QACnC,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,wBAAwB;QACxB,YAAY;QACZ,oBAAoB;KACrB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,iBAAiB,EACjB,sBAAsB,GAMvB,EAAE,EAAE;IACH,MAAM,EAAE,gBAAgB,GAAG,GAAG,EAAE,GAAG,sBAAyC,CAAC;IAC7E,OAAO,iCAAiC,CACtC,iBAAwD,EACxD,gBAAgB,CACjB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n GasFeeEstimates,\n GasFeeState,\n} from '@metamask/gas-fee-controller';\nimport type {\n FeeMarketGasFeeEstimates,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nconst getTransaction1559GasFeeEstimates = (\n txGasFeeEstimates: FeeMarketGasFeeEstimates,\n estimatedBaseFee: string,\n) => {\n const { maxFeePerGas, maxPriorityFeePerGas } = txGasFeeEstimates?.high ?? {};\n\n const baseAndPriorityFeePerGas = maxPriorityFeePerGas\n ? new BigNumber(estimatedBaseFee, 10)\n .times(10 ** 9)\n .plus(maxPriorityFeePerGas, 16)\n : undefined;\n\n return {\n baseAndPriorityFeePerGas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n };\n};\n\n/**\n * Get the gas fee estimates for a transaction\n *\n * @param params - The parameters for the gas fee estimates\n * @param params.txGasFeeEstimates - The gas fee estimates for the transaction (TransactionController)\n * @param params.networkGasFeeEstimates - The gas fee estimates for the network (GasFeeController)\n * @returns The gas fee estimates for the transaction\n */\nexport const getTxGasEstimates = ({\n txGasFeeEstimates,\n networkGasFeeEstimates,\n}: {\n txGasFeeEstimates: Awaited<\n ReturnType<TransactionController['estimateGasFee']>\n >['estimates'];\n networkGasFeeEstimates: GasFeeState['gasFeeEstimates'];\n}) => {\n const { estimatedBaseFee = '0' } = networkGasFeeEstimates as GasFeeEstimates;\n return getTransaction1559GasFeeEstimates(\n txGasFeeEstimates as unknown as FeeMarketGasFeeEstimates,\n estimatedBaseFee,\n );\n};\n"]}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isSmartTransactionsEnabled = void 0;
|
4
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
5
|
+
/**
|
6
|
+
* Check if smart transactions are enabled
|
7
|
+
*
|
8
|
+
* @param txType - The type of transaction
|
9
|
+
* @param defaultStxPreference - The default preference for smart transactions for the client
|
10
|
+
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client
|
11
|
+
* @param isUserOptedInToStx - Whether the user has opted in to smart transactions
|
12
|
+
* @returns Whether smart transactions should be used for the transaction
|
13
|
+
*/
|
14
|
+
const isSmartTransactionsEnabled = (txType, defaultStxPreference, isStxEnabledOnClient, isUserOptedInToStx) => {
|
15
|
+
return (txType === transaction_controller_1.TransactionType.bridge &&
|
16
|
+
// If user has no opt in status, use default value from client
|
17
|
+
(isUserOptedInToStx ?? defaultStxPreference) &&
|
18
|
+
isStxEnabledOnClient);
|
19
|
+
};
|
20
|
+
exports.isSmartTransactionsEnabled = isSmartTransactionsEnabled;
|
21
|
+
//# sourceMappingURL=smart-transactions.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"smart-transactions.cjs","sourceRoot":"","sources":["../../src/utils/smart-transactions.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;AAEnE;;;;;;;;GAQG;AACI,MAAM,0BAA0B,GAAG,CACxC,MAAuB,EACvB,oBAA6B,EAC7B,oBAA6B,EAC7B,kBAA4B,EAC5B,EAAE;IACF,OAAO,CACL,MAAM,KAAK,wCAAe,CAAC,MAAM;QACjC,8DAA8D;QAC9D,CAAC,kBAAkB,IAAI,oBAAoB,CAAC;QAC5C,oBAAoB,CACrB,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,0BAA0B,8BAYrC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\n\n/**\n * Check if smart transactions are enabled\n *\n * @param txType - The type of transaction\n * @param defaultStxPreference - The default preference for smart transactions for the client\n * @param isStxEnabledOnClient - Whether smart transactions are enabled on the client\n * @param isUserOptedInToStx - Whether the user has opted in to smart transactions\n * @returns Whether smart transactions should be used for the transaction\n */\nexport const isSmartTransactionsEnabled = (\n txType: TransactionType,\n defaultStxPreference: boolean,\n isStxEnabledOnClient: boolean,\n isUserOptedInToStx?: boolean,\n) => {\n return (\n txType === TransactionType.bridge &&\n // If user has no opt in status, use default value from client\n (isUserOptedInToStx ?? defaultStxPreference) &&\n isStxEnabledOnClient\n );\n};\n"]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
2
|
+
/**
|
3
|
+
* Check if smart transactions are enabled
|
4
|
+
*
|
5
|
+
* @param txType - The type of transaction
|
6
|
+
* @param defaultStxPreference - The default preference for smart transactions for the client
|
7
|
+
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client
|
8
|
+
* @param isUserOptedInToStx - Whether the user has opted in to smart transactions
|
9
|
+
* @returns Whether smart transactions should be used for the transaction
|
10
|
+
*/
|
11
|
+
export declare const isSmartTransactionsEnabled: (txType: TransactionType, defaultStxPreference: boolean, isStxEnabledOnClient: boolean, isUserOptedInToStx?: boolean) => boolean;
|
12
|
+
//# sourceMappingURL=smart-transactions.d.cts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"smart-transactions.d.cts","sourceRoot":"","sources":["../../src/utils/smart-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,WAC7B,eAAe,wBACD,OAAO,wBACP,OAAO,uBACR,OAAO,YAQ7B,CAAC"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
2
|
+
/**
|
3
|
+
* Check if smart transactions are enabled
|
4
|
+
*
|
5
|
+
* @param txType - The type of transaction
|
6
|
+
* @param defaultStxPreference - The default preference for smart transactions for the client
|
7
|
+
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client
|
8
|
+
* @param isUserOptedInToStx - Whether the user has opted in to smart transactions
|
9
|
+
* @returns Whether smart transactions should be used for the transaction
|
10
|
+
*/
|
11
|
+
export declare const isSmartTransactionsEnabled: (txType: TransactionType, defaultStxPreference: boolean, isStxEnabledOnClient: boolean, isUserOptedInToStx?: boolean) => boolean;
|
12
|
+
//# sourceMappingURL=smart-transactions.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"smart-transactions.d.mts","sourceRoot":"","sources":["../../src/utils/smart-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,WAC7B,eAAe,wBACD,OAAO,wBACP,OAAO,uBACR,OAAO,YAQ7B,CAAC"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
2
|
+
/**
|
3
|
+
* Check if smart transactions are enabled
|
4
|
+
*
|
5
|
+
* @param txType - The type of transaction
|
6
|
+
* @param defaultStxPreference - The default preference for smart transactions for the client
|
7
|
+
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client
|
8
|
+
* @param isUserOptedInToStx - Whether the user has opted in to smart transactions
|
9
|
+
* @returns Whether smart transactions should be used for the transaction
|
10
|
+
*/
|
11
|
+
export const isSmartTransactionsEnabled = (txType, defaultStxPreference, isStxEnabledOnClient, isUserOptedInToStx) => {
|
12
|
+
return (txType === TransactionType.bridge &&
|
13
|
+
// If user has no opt in status, use default value from client
|
14
|
+
(isUserOptedInToStx ?? defaultStxPreference) &&
|
15
|
+
isStxEnabledOnClient);
|
16
|
+
};
|
17
|
+
//# sourceMappingURL=smart-transactions.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"smart-transactions.mjs","sourceRoot":"","sources":["../../src/utils/smart-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,MAAuB,EACvB,oBAA6B,EAC7B,oBAA6B,EAC7B,kBAA4B,EAC5B,EAAE;IACF,OAAO,CACL,MAAM,KAAK,eAAe,CAAC,MAAM;QACjC,8DAA8D;QAC9D,CAAC,kBAAkB,IAAI,oBAAoB,CAAC;QAC5C,oBAAoB,CACrB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\n\n/**\n * Check if smart transactions are enabled\n *\n * @param txType - The type of transaction\n * @param defaultStxPreference - The default preference for smart transactions for the client\n * @param isStxEnabledOnClient - Whether smart transactions are enabled on the client\n * @param isUserOptedInToStx - Whether the user has opted in to smart transactions\n * @returns Whether smart transactions should be used for the transaction\n */\nexport const isSmartTransactionsEnabled = (\n txType: TransactionType,\n defaultStxPreference: boolean,\n isStxEnabledOnClient: boolean,\n isUserOptedInToStx?: boolean,\n) => {\n return (\n txType === TransactionType.bridge &&\n // If user has no opt in status, use default value from client\n (isUserOptedInToStx ?? defaultStxPreference) &&\n isStxEnabledOnClient\n );\n};\n"]}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getKeyringRequest = exports.handleLineaDelay = exports.handleSolanaTxResponse = exports.getTxMetaFields = exports.getStatusRequestParams = exports.generateActionId = void 0;
|
4
|
+
const bridge_controller_1 = require("@metamask/bridge-controller");
|
5
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
6
|
+
const utils_1 = require("@metamask/utils");
|
7
|
+
const uuid_1 = require("uuid");
|
8
|
+
const constants_1 = require("../constants.cjs");
|
9
|
+
const generateActionId = () => (Date.now() + Math.random()).toString();
|
10
|
+
exports.generateActionId = generateActionId;
|
11
|
+
const getStatusRequestParams = (quoteResponse) => {
|
12
|
+
return {
|
13
|
+
bridgeId: quoteResponse.quote.bridgeId,
|
14
|
+
bridge: quoteResponse.quote.bridges[0],
|
15
|
+
srcChainId: quoteResponse.quote.srcChainId,
|
16
|
+
destChainId: quoteResponse.quote.destChainId,
|
17
|
+
quote: quoteResponse.quote,
|
18
|
+
refuel: Boolean(quoteResponse.quote.refuel),
|
19
|
+
};
|
20
|
+
};
|
21
|
+
exports.getStatusRequestParams = getStatusRequestParams;
|
22
|
+
const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
23
|
+
return {
|
24
|
+
destinationChainId: (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.destChainId),
|
25
|
+
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
26
|
+
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
27
|
+
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
28
|
+
sourceTokenAddress: quoteResponse.quote.srcAsset.address,
|
29
|
+
destinationTokenAmount: quoteResponse.quote.destTokenAmount,
|
30
|
+
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
31
|
+
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
32
|
+
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
33
|
+
chainId: (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId),
|
34
|
+
approvalTxId,
|
35
|
+
// this is the decimal (non atomic) amount (not USD value) of source token to swap
|
36
|
+
swapTokenValue: quoteResponse.sentAmount.amount,
|
37
|
+
};
|
38
|
+
};
|
39
|
+
exports.getTxMetaFields = getTxMetaFields;
|
40
|
+
const handleSolanaTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
41
|
+
const selectedAccountAddress = selectedAccount.address;
|
42
|
+
const snapId = selectedAccount.metadata.snap?.id;
|
43
|
+
let hash;
|
44
|
+
// Handle different response formats
|
45
|
+
if (typeof snapResponse === 'string') {
|
46
|
+
hash = snapResponse;
|
47
|
+
}
|
48
|
+
else if (snapResponse && typeof snapResponse === 'object') {
|
49
|
+
// If it's an object with result property, try to get the signature
|
50
|
+
if (snapResponse.result && typeof snapResponse.result === 'object') {
|
51
|
+
// Try to extract signature from common locations in response object
|
52
|
+
hash =
|
53
|
+
snapResponse.result.signature ||
|
54
|
+
snapResponse.result.txid ||
|
55
|
+
snapResponse.result.hash ||
|
56
|
+
snapResponse.result.txHash;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
|
60
|
+
// Create a transaction meta object with bridge-specific fields
|
61
|
+
return {
|
62
|
+
...(0, exports.getTxMetaFields)(quoteResponse),
|
63
|
+
time: Date.now(),
|
64
|
+
id: (0, uuid_1.v4)(),
|
65
|
+
chainId: hexChainId,
|
66
|
+
networkClientId: snapId ?? hexChainId,
|
67
|
+
txParams: { from: selectedAccountAddress, data: quoteResponse.trade },
|
68
|
+
type: transaction_controller_1.TransactionType.bridge,
|
69
|
+
status: transaction_controller_1.TransactionStatus.submitted,
|
70
|
+
hash,
|
71
|
+
origin: snapId,
|
72
|
+
// Add an explicit bridge flag to mark this as a Solana transaction
|
73
|
+
isSolana: true,
|
74
|
+
isBridgeTx: true, // TODO deprecate this and use type
|
75
|
+
};
|
76
|
+
};
|
77
|
+
exports.handleSolanaTxResponse = handleSolanaTxResponse;
|
78
|
+
const handleLineaDelay = async (quoteResponse) => {
|
79
|
+
if (bridge_controller_1.ChainId.LINEA === quoteResponse.quote.srcChainId) {
|
80
|
+
const debugLog = (0, utils_1.createProjectLogger)('bridge');
|
81
|
+
debugLog('Delaying submitting bridge tx to make Linea confirmation more likely');
|
82
|
+
const waitPromise = new Promise((resolve) => setTimeout(resolve, constants_1.LINEA_DELAY_MS));
|
83
|
+
await waitPromise;
|
84
|
+
}
|
85
|
+
};
|
86
|
+
exports.handleLineaDelay = handleLineaDelay;
|
87
|
+
const getKeyringRequest = (quoteResponse, selectedAccount) => {
|
88
|
+
const keyringReqId = (0, uuid_1.v4)();
|
89
|
+
const snapRequestId = (0, uuid_1.v4)();
|
90
|
+
return {
|
91
|
+
origin: 'metamask',
|
92
|
+
snapId: selectedAccount.metadata.snap?.id,
|
93
|
+
handler: 'onKeyringRequest',
|
94
|
+
request: {
|
95
|
+
id: keyringReqId,
|
96
|
+
jsonrpc: '2.0',
|
97
|
+
method: 'keyring_submitRequest',
|
98
|
+
params: {
|
99
|
+
request: {
|
100
|
+
params: {
|
101
|
+
account: { address: selectedAccount.address },
|
102
|
+
transaction: quoteResponse.trade,
|
103
|
+
scope: selectedAccount.options.scope,
|
104
|
+
},
|
105
|
+
method: 'signAndSendTransaction',
|
106
|
+
},
|
107
|
+
id: snapRequestId,
|
108
|
+
account: selectedAccount.id,
|
109
|
+
scope: selectedAccount.options.scope,
|
110
|
+
},
|
111
|
+
},
|
112
|
+
};
|
113
|
+
};
|
114
|
+
exports.getKeyringRequest = getKeyringRequest;
|
115
|
+
//# sourceMappingURL=transaction.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAEA,mEAKqC;AACrC,6EAI0C;AAC1C,2CAAsD;AACtD,+BAAkC;AAElC,gDAA8C;AAGvC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAAjE,QAAA,gBAAgB,oBAAiD;AAEvE,MAAM,sBAAsB,GAAG,CACpC,aAA6C,EAC7C,EAAE;IACF,OAAO;QACL,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ;QACtC,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACtC,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,UAAU;QAC1C,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,WAAW;QAC5C,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;KAC5C,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,sBAAsB,0BAWjC;AAEK,MAAM,eAAe,GAAG,CAC7B,aACe,EACf,YAAqB,EAIrB,EAAE;IACF,OAAO;QACL,kBAAkB,EAAE,IAAA,sCAAkB,EAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC;QACvE,iBAAiB,EAAE,aAAa,CAAC,KAAK,CAAC,cAAc;QACrD,iBAAiB,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ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A,SAAI,GAAE,CAAC;IAE7B,OAAO;QACL,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAW;QAClD,OAAO,EAAE,kBAA2B;QACpC,OAAO,EAAE;YACP,EAAE,EAAE,YAAY;YAChB,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,uBAAuB;YAC/B,MAAM,EAAE;gBACN,OAAO,EAAE;oBACP,MAAM,EAAE;wBACN,OAAO,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE;wBAC7C,WAAW,EAAE,aAAa,CAAC,KAAK;wBAChC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK;qBACrC;oBACD,MAAM,EAAE,wBAAwB;iBACjC;gBACD,EAAE,EAAE,aAAa;gBACjB,OAAO,EAAE,eAAe,CAAC,EAAE;gBAC3B,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK;aACrC;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,iBAAiB,qBA8B5B","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n ChainId,\n formatChainIdToHex,\n type QuoteMetadata,\n type QuoteResponse,\n} from '@metamask/bridge-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { LINEA_DELAY_MS } from '../constants';\nimport type { SolanaTransactionMeta } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (\n quoteResponse: QuoteResponse<string | TxData>,\n) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'\n> => {\n return {\n destinationChainId: formatChainIdToHex(quoteResponse.quote.destChainId),\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n chainId: formatChainIdToHex(quoteResponse.quote.srcChainId),\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\nexport const handleSolanaTxResponse = (\n snapResponse: string | { result: Record<string, string> },\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // If it's an object with result property, try to get the signature\n if (snapResponse.result && typeof snapResponse.result === 'object') {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n }\n }\n\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: quoteResponse.trade },\n type: TransactionType.bridge,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit bridge flag to mark this as a Solana transaction\n isSolana: true, // TODO deprecate this and use chainId\n isBridgeTx: true, // TODO deprecate this and use type\n };\n};\n\nexport const handleLineaDelay = async (\n quoteResponse: QuoteResponse<TxData | string>,\n) => {\n if (ChainId.LINEA === quoteResponse.quote.srcChainId) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, LINEA_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\nexport const getKeyringRequest = (\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const keyringReqId = uuid();\n const snapRequestId = uuid();\n\n return {\n origin: 'metamask',\n snapId: selectedAccount.metadata.snap?.id as never,\n handler: 'onKeyringRequest' as never,\n request: {\n id: keyringReqId,\n jsonrpc: '2.0',\n method: 'keyring_submitRequest',\n params: {\n request: {\n params: {\n account: { address: selectedAccount.address },\n transaction: quoteResponse.trade,\n scope: selectedAccount.options.scope,\n },\n method: 'signAndSendTransaction',\n },\n id: snapRequestId,\n account: selectedAccount.id,\n scope: selectedAccount.options.scope,\n },\n },\n };\n};\n"]}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import type { AccountsControllerState } from "@metamask/accounts-controller";
|
2
|
+
import type { TxData } from "@metamask/bridge-controller";
|
3
|
+
import { ChainId, type QuoteMetadata, type QuoteResponse } from "@metamask/bridge-controller";
|
4
|
+
import { type TransactionMeta } from "@metamask/transaction-controller";
|
5
|
+
import type { SolanaTransactionMeta } from "../types.cjs";
|
6
|
+
export declare const generateActionId: () => string;
|
7
|
+
export declare const getStatusRequestParams: (quoteResponse: QuoteResponse<string | TxData>) => {
|
8
|
+
bridgeId: string;
|
9
|
+
bridge: string;
|
10
|
+
srcChainId: ChainId;
|
11
|
+
destChainId: ChainId;
|
12
|
+
quote: import("@metamask/bridge-controller").Quote;
|
13
|
+
refuel: boolean;
|
14
|
+
};
|
15
|
+
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'>;
|
16
|
+
export declare const handleSolanaTxResponse: (snapResponse: string | {
|
17
|
+
result: Record<string, string>;
|
18
|
+
}, quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => TransactionMeta & SolanaTransactionMeta;
|
19
|
+
export declare const handleLineaDelay: (quoteResponse: QuoteResponse<TxData | string>) => Promise<void>;
|
20
|
+
export declare const getKeyringRequest: (quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => {
|
21
|
+
origin: string;
|
22
|
+
snapId: never;
|
23
|
+
handler: never;
|
24
|
+
request: {
|
25
|
+
id: string;
|
26
|
+
jsonrpc: string;
|
27
|
+
method: string;
|
28
|
+
params: {
|
29
|
+
request: {
|
30
|
+
params: {
|
31
|
+
account: {
|
32
|
+
address: string;
|
33
|
+
};
|
34
|
+
transaction: string;
|
35
|
+
scope: import("@metamask/utils").Json;
|
36
|
+
};
|
37
|
+
method: string;
|
38
|
+
};
|
39
|
+
id: string;
|
40
|
+
account: string;
|
41
|
+
scope: import("@metamask/utils").Json;
|
42
|
+
};
|
43
|
+
};
|
44
|
+
};
|
45
|
+
//# sourceMappingURL=transaction.d.cts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,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xData } from "@metamask/bridge-controller";
|
3
|
+
import { ChainId, type QuoteMetadata, type QuoteResponse } from "@metamask/bridge-controller";
|
4
|
+
import { type TransactionMeta } from "@metamask/transaction-controller";
|
5
|
+
import type { SolanaTransactionMeta } from "../types.mjs";
|
6
|
+
export declare const generateActionId: () => string;
|
7
|
+
export declare const getStatusRequestParams: (quoteResponse: QuoteResponse<string | TxData>) => {
|
8
|
+
bridgeId: string;
|
9
|
+
bridge: string;
|
10
|
+
srcChainId: ChainId;
|
11
|
+
destChainId: ChainId;
|
12
|
+
quote: import("@metamask/bridge-controller").Quote;
|
13
|
+
refuel: boolean;
|
14
|
+
};
|
15
|
+
export declare const getTxMetaFields: (quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> & QuoteMetadata, approvalTxId?: string) => Omit<TransactionMeta, 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'>;
|
16
|
+
export declare const handleSolanaTxResponse: (snapResponse: string | {
|
17
|
+
result: Record<string, string>;
|
18
|
+
}, quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => TransactionMeta & SolanaTransactionMeta;
|
19
|
+
export declare const handleLineaDelay: (quoteResponse: QuoteResponse<TxData | string>) => Promise<void>;
|
20
|
+
export declare const getKeyringRequest: (quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata, selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string]) => {
|
21
|
+
origin: string;
|
22
|
+
snapId: never;
|
23
|
+
handler: never;
|
24
|
+
request: {
|
25
|
+
id: string;
|
26
|
+
jsonrpc: string;
|
27
|
+
method: string;
|
28
|
+
params: {
|
29
|
+
request: {
|
30
|
+
params: {
|
31
|
+
account: {
|
32
|
+
address: string;
|
33
|
+
};
|
34
|
+
transaction: string;
|
35
|
+
scope: import("@metamask/utils").Json;
|
36
|
+
};
|
37
|
+
method: string;
|
38
|
+
};
|
39
|
+
id: string;
|
40
|
+
account: string;
|
41
|
+
scope: import("@metamask/utils").Json;
|
42
|
+
};
|
43
|
+
};
|
44
|
+
};
|
45
|
+
//# sourceMappingURL=transaction.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAsC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,oCAAoC;AAC1D,OAAO,EACL,OAAO,EAEP,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,oCAAoC;AACrC,OAAO,EAGL,KAAK,eAAe,EACrB,yCAAyC;AAK1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD,eAAO,MAAM,gBAAgB,cAAgD,CAAC;AAE9E,eAAO,MAAM,sBAAsB,kBAClB,cAAc,MAAM,GAAG,MAAM,CAAC;;;;;;;CAU9C,CAAC;AAEF,eAAO,MAAM,eAAe,kBACX,KAAK,cAAc,MAAM,GAAG,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,GACvE,aAAa,iBACA,MAAM,KACpB,KACD,eAAe,EACf,iBAAiB,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAmB1D,CAAC;AAEF,eAAO,MAAM,sBAAsB,iBACnB,MAAM,GAAG;IAAE,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,iBAC1C,KAAK,cAAc,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,aAAa,mBACrD,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAC/E,eAAe,GAAG,qBAoCpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,kBACZ,cAAc,MAAM,GAAG,MAAM,CAAC,kBAY9C,CAAC;AAEF,eAAO,MAAM,iBAAiB,kBACb,KAAK,cAAc,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,aAAa,mBACrD,uBAAuB,CAAC,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;CA4BjF,CAAC"}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import { ChainId, formatChainIdToHex } from "@metamask/bridge-controller";
|
2
|
+
import { TransactionStatus, TransactionType } from "@metamask/transaction-controller";
|
3
|
+
import { createProjectLogger } from "@metamask/utils";
|
4
|
+
import { v4 as uuid } from "uuid";
|
5
|
+
import { LINEA_DELAY_MS } from "../constants.mjs";
|
6
|
+
export const generateActionId = () => (Date.now() + Math.random()).toString();
|
7
|
+
export const getStatusRequestParams = (quoteResponse) => {
|
8
|
+
return {
|
9
|
+
bridgeId: quoteResponse.quote.bridgeId,
|
10
|
+
bridge: quoteResponse.quote.bridges[0],
|
11
|
+
srcChainId: quoteResponse.quote.srcChainId,
|
12
|
+
destChainId: quoteResponse.quote.destChainId,
|
13
|
+
quote: quoteResponse.quote,
|
14
|
+
refuel: Boolean(quoteResponse.quote.refuel),
|
15
|
+
};
|
16
|
+
};
|
17
|
+
export const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
18
|
+
return {
|
19
|
+
destinationChainId: formatChainIdToHex(quoteResponse.quote.destChainId),
|
20
|
+
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
21
|
+
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
22
|
+
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
23
|
+
sourceTokenAddress: quoteResponse.quote.srcAsset.address,
|
24
|
+
destinationTokenAmount: quoteResponse.quote.destTokenAmount,
|
25
|
+
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
26
|
+
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
27
|
+
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
28
|
+
chainId: formatChainIdToHex(quoteResponse.quote.srcChainId),
|
29
|
+
approvalTxId,
|
30
|
+
// this is the decimal (non atomic) amount (not USD value) of source token to swap
|
31
|
+
swapTokenValue: quoteResponse.sentAmount.amount,
|
32
|
+
};
|
33
|
+
};
|
34
|
+
export const handleSolanaTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
35
|
+
const selectedAccountAddress = selectedAccount.address;
|
36
|
+
const snapId = selectedAccount.metadata.snap?.id;
|
37
|
+
let hash;
|
38
|
+
// Handle different response formats
|
39
|
+
if (typeof snapResponse === 'string') {
|
40
|
+
hash = snapResponse;
|
41
|
+
}
|
42
|
+
else if (snapResponse && typeof snapResponse === 'object') {
|
43
|
+
// If it's an object with result property, try to get the signature
|
44
|
+
if (snapResponse.result && typeof snapResponse.result === 'object') {
|
45
|
+
// Try to extract signature from common locations in response object
|
46
|
+
hash =
|
47
|
+
snapResponse.result.signature ||
|
48
|
+
snapResponse.result.txid ||
|
49
|
+
snapResponse.result.hash ||
|
50
|
+
snapResponse.result.txHash;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
54
|
+
// Create a transaction meta object with bridge-specific fields
|
55
|
+
return {
|
56
|
+
...getTxMetaFields(quoteResponse),
|
57
|
+
time: Date.now(),
|
58
|
+
id: uuid(),
|
59
|
+
chainId: hexChainId,
|
60
|
+
networkClientId: snapId ?? hexChainId,
|
61
|
+
txParams: { from: selectedAccountAddress, data: quoteResponse.trade },
|
62
|
+
type: TransactionType.bridge,
|
63
|
+
status: TransactionStatus.submitted,
|
64
|
+
hash,
|
65
|
+
origin: snapId,
|
66
|
+
// Add an explicit bridge flag to mark this as a Solana transaction
|
67
|
+
isSolana: true,
|
68
|
+
isBridgeTx: true, // TODO deprecate this and use type
|
69
|
+
};
|
70
|
+
};
|
71
|
+
export const handleLineaDelay = async (quoteResponse) => {
|
72
|
+
if (ChainId.LINEA === quoteResponse.quote.srcChainId) {
|
73
|
+
const debugLog = createProjectLogger('bridge');
|
74
|
+
debugLog('Delaying submitting bridge tx to make Linea confirmation more likely');
|
75
|
+
const waitPromise = new Promise((resolve) => setTimeout(resolve, LINEA_DELAY_MS));
|
76
|
+
await waitPromise;
|
77
|
+
}
|
78
|
+
};
|
79
|
+
export const getKeyringRequest = (quoteResponse, selectedAccount) => {
|
80
|
+
const keyringReqId = uuid();
|
81
|
+
const snapRequestId = uuid();
|
82
|
+
return {
|
83
|
+
origin: 'metamask',
|
84
|
+
snapId: selectedAccount.metadata.snap?.id,
|
85
|
+
handler: 'onKeyringRequest',
|
86
|
+
request: {
|
87
|
+
id: keyringReqId,
|
88
|
+
jsonrpc: '2.0',
|
89
|
+
method: 'keyring_submitRequest',
|
90
|
+
params: {
|
91
|
+
request: {
|
92
|
+
params: {
|
93
|
+
account: { address: selectedAccount.address },
|
94
|
+
transaction: quoteResponse.trade,
|
95
|
+
scope: selectedAccount.options.scope,
|
96
|
+
},
|
97
|
+
method: 'signAndSendTransaction',
|
98
|
+
},
|
99
|
+
id: snapRequestId,
|
100
|
+
account: selectedAccount.id,
|
101
|
+
scope: selectedAccount.options.scope,
|
102
|
+
},
|
103
|
+
},
|
104
|
+
};
|
105
|
+
};
|
106
|
+
//# sourceMappingURL=transaction.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,kBAAkB,EAGnB,oCAAoC;AACrC,OAAO,EACL,iBAAiB,EACjB,eAAe,EAEhB,yCAAyC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB;AACtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,cAAc,EAAE,yBAAqB;AAG9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAE9E,M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amask/accounts-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n ChainId,\n formatChainIdToHex,\n type QuoteMetadata,\n type QuoteResponse,\n} from '@metamask/bridge-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport { LINEA_DELAY_MS } from '../constants';\nimport type { SolanaTransactionMeta } from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getStatusRequestParams = (\n quoteResponse: QuoteResponse<string | TxData>,\n) => {\n return {\n bridgeId: quoteResponse.quote.bridgeId,\n bridge: quoteResponse.quote.bridges[0],\n srcChainId: quoteResponse.quote.srcChainId,\n destChainId: quoteResponse.quote.destChainId,\n quote: quoteResponse.quote,\n refuel: Boolean(quoteResponse.quote.refuel),\n };\n};\n\nexport const getTxMetaFields = (\n quoteResponse: Omit<QuoteResponse<string | TxData>, 'approval' | 'trade'> &\n QuoteMetadata,\n approvalTxId?: string,\n): Omit<\n TransactionMeta,\n 'networkClientId' | 'status' | 'time' | 'txParams' | 'id'\n> => {\n return {\n destinationChainId: formatChainIdToHex(quoteResponse.quote.destChainId),\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n chainId: formatChainIdToHex(quoteResponse.quote.srcChainId),\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\nexport const handleSolanaTxResponse = (\n snapResponse: string | { result: Record<string, string> },\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // If it's an object with result property, try to get the signature\n if (snapResponse.result && typeof snapResponse.result === 'object') {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n }\n }\n\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: quoteResponse.trade },\n type: TransactionType.bridge,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit bridge flag to mark this as a Solana transaction\n isSolana: true, // TODO deprecate this and use chainId\n isBridgeTx: true, // TODO deprecate this and use type\n };\n};\n\nexport const handleLineaDelay = async (\n quoteResponse: QuoteResponse<TxData | string>,\n) => {\n if (ChainId.LINEA === quoteResponse.quote.srcChainId) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, LINEA_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\nexport const getKeyringRequest = (\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const keyringReqId = uuid();\n const snapRequestId = uuid();\n\n return {\n origin: 'metamask',\n snapId: selectedAccount.metadata.snap?.id as never,\n handler: 'onKeyringRequest' as never,\n request: {\n id: keyringReqId,\n jsonrpc: '2.0',\n method: 'keyring_submitRequest',\n params: {\n request: {\n params: {\n account: { address: selectedAccount.address },\n transaction: quoteResponse.trade,\n scope: selectedAccount.options.scope,\n },\n method: 'signAndSendTransaction',\n },\n id: snapRequestId,\n account: selectedAccount.id,\n scope: selectedAccount.options.scope,\n },\n },\n };\n};\n"]}
|
@@ -31,7 +31,7 @@ const validateBridgeStatusResponse = (data) => {
|
|
31
31
|
status: (0, superstruct_1.enums)(Object.values(types_1.StatusTypes)),
|
32
32
|
srcChain: SrcChainStatusSchema,
|
33
33
|
destChain: (0, superstruct_1.optional)(DestChainStatusSchema),
|
34
|
-
bridge: (0, superstruct_1.optional)((0, superstruct_1.
|
34
|
+
bridge: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
35
35
|
isExpectedToken: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
36
36
|
isUnrecognizedRouterAddress: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
37
37
|
refuel: (0, superstruct_1.optional)(RefuelStatusResponseSchema),
|