@metamask-previews/bridge-status-controller 44.0.0-preview-8ccfcb37 → 44.0.0-preview-b896289e
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 +2 -28
- package/dist/bridge-status-controller.cjs +44 -47
- 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 +45 -48
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/transaction.cjs +38 -69
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +27 -37
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +27 -37
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +37 -68
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/utils/snaps.cjs +0 -35
- package/dist/utils/snaps.cjs.map +0 -1
- package/dist/utils/snaps.d.cts +0 -29
- package/dist/utils/snaps.d.cts.map +0 -1
- package/dist/utils/snaps.d.mts +0 -29
- package/dist/utils/snaps.d.mts.map +0 -1
- package/dist/utils/snaps.mjs +0 -31
- package/dist/utils/snaps.mjs.map +0 -1
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsCA,8EAA8E;AAC9E,2BAA2B;AAE3B,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AA0CD,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,qCAAyB,CAAA;IACzB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,wBAAR,QAAQ,QAanB;AA2CD,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,0FAAoE,CAAA;IACpE,6DAAuC,CAAA;IACvC,4CAAsB,CAAA;IACtB,gDAA0B,CAAA;IAC1B,4CAAsB,CAAA;IACtB,6FAAuE,CAAA;IACvE,8FAAwE,CAAA;AAC1E,CAAC,EARW,kBAAkB,kCAAlB,kBAAkB,QAQ7B","sourcesContent":["import type {\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n BridgeBackgroundAction,\n BridgeControllerAction,\n ChainId,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n TransactionControllerGetStateAction,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type { BridgeStatusController } from './bridge-status-controller';\nimport type { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';\nimport type { StatusResponseSchema } from './utils/validators';\n\n// All fields need to be types not interfaces, same with their children fields\n// o/w you get a type error\n\nexport enum BridgeClientId {\n EXTENSION = 'extension',\n MOBILE = 'mobile',\n}\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * These fields are specific to Solana transactions and can likely be infered from TransactionMeta\n *\n * @deprecated these should be removed eventually\n */\nexport type SolanaTransactionMeta = {\n isSolana: boolean;\n isBridgeTx: boolean;\n};\n\nexport type StatusRequest = {\n bridgeId: string; // lifi, socket, squid\n srcTxHash?: string; // lifi, socket, squid, might be undefined for STX\n bridge: string; // lifi, socket, squid\n srcChainId: ChainId; // lifi, socket, squid\n destChainId: ChainId; // lifi, socket, squid\n quote?: Quote; // squid\n refuel?: boolean; // lifi\n};\n\nexport type StatusRequestDto = Omit<\n StatusRequest,\n 'quote' | 'srcChainId' | 'destChainId' | 'refuel'\n> & {\n srcChainId: string; // lifi, socket, squid\n destChainId: string; // lifi, socket, squid\n requestId?: string;\n refuel?: string; // lifi\n};\n\nexport type StatusRequestWithSrcTxHash = StatusRequest & {\n srcTxHash: string;\n};\n\nexport enum BridgeId {\n HOP = 'hop',\n CELER = 'celer',\n CELERCIRCLE = 'celercircle',\n CONNEXT = 'connext',\n POLYGON = 'polygon',\n AVALANCHE = 'avalanche',\n MULTICHAIN = 'multichain',\n AXELAR = 'axelar',\n ACROSS = 'across',\n STARGATE = 'stargate',\n RELAY = 'relay',\n MAYAN = 'mayan',\n}\n\nexport type StatusResponse = Infer<typeof StatusResponseSchema>;\n\nexport type RefuelStatusResponse = object & StatusResponse;\n\nexport type BridgeHistoryItem = {\n txMetaId: string; // Need this to handle STX that might not have a txHash immediately\n batchId?: string;\n quote: Quote;\n status: StatusResponse;\n startTime?: number; // timestamp in ms\n estimatedProcessingTimeInSeconds: number;\n slippagePercentage: number;\n completionTime?: number; // timestamp in ms\n pricingData?: {\n /**\n * The actual amount sent by user in non-atomic decimal form\n */\n amountSent: QuoteMetadata['sentAmount']['amount'];\n amountSentInUsd?: QuoteMetadata['sentAmount']['usd'];\n quotedGasInUsd?: QuoteMetadata['gasFee']['effective']['usd'];\n quotedGasAmount?: QuoteMetadata['gasFee']['effective']['amount'];\n quotedReturnInUsd?: QuoteMetadata['toTokenAmount']['usd'];\n quotedRefuelSrcAmountInUsd?: string;\n quotedRefuelDestAmountInUsd?: string;\n };\n initialDestAssetBalance?: string;\n targetContractAddress?: string;\n account: string;\n hasApprovalTx: boolean;\n approvalTxId?: string;\n isStxEnabled?: boolean;\n /**\n * Attempts tracking for exponential backoff on failed fetches.\n * We track the number of attempts and the last attempt time for each txMetaId that has failed at least once\n */\n attempts?: {\n counter: number;\n lastAttemptTime: number; // timestamp in ms\n };\n};\n\nexport enum BridgeStatusAction {\n START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',\n WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',\n GET_STATE = 'getState',\n RESET_STATE = 'resetState',\n SUBMIT_TX = 'submitTx',\n RESTART_POLLING_FOR_FAILED_ATTEMPTS = 'restartPollingForFailedAttempts',\n GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID = 'getBridgeHistoryItemByTxMetaId',\n}\n\nexport type TokenAmountValuesSerialized = {\n amount: string;\n valueInCurrency: string | null;\n usd: string | null;\n};\n\nexport type QuoteMetadataSerialized = {\n gasFee: TokenAmountValuesSerialized;\n /**\n * The total network fee for the bridge transaction\n * estimatedGasFees + relayerFees\n */\n totalNetworkFee: TokenAmountValuesSerialized;\n /**\n * The total max network fee for the bridge transaction\n * maxGasFees + relayerFees\n */\n totalMaxNetworkFee: TokenAmountValuesSerialized;\n toTokenAmount: TokenAmountValuesSerialized;\n /**\n * The adjusted return for the bridge transaction\n * destTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValuesSerialized, 'amount'>;\n /**\n * The actual amount sent by user in non-atomic decimal form\n * srcTokenAmount + metabridgeFee\n */\n sentAmount: TokenAmountValuesSerialized;\n swapRate: string; // destTokenAmount / sentAmount\n /**\n * The cost of the bridge transaction\n * sentAmount - adjustedReturn\n */\n cost: Omit<TokenAmountValuesSerialized, 'amount'>;\n};\n\nexport type StartPollingForBridgeTxStatusArgs = {\n bridgeTxMeta: TransactionMeta;\n statusRequest: StatusRequest;\n quoteResponse: QuoteResponse & QuoteMetadata;\n startTime?: BridgeHistoryItem['startTime'];\n slippagePercentage: BridgeHistoryItem['slippagePercentage'];\n initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];\n targetContractAddress?: BridgeHistoryItem['targetContractAddress'];\n approvalTxId?: BridgeHistoryItem['approvalTxId'];\n isStxEnabled?: BridgeHistoryItem['isStxEnabled'];\n accountAddress: string;\n};\n\n/**\n * Chrome: The BigNumber values are automatically serialized to strings when sent to the background\n * Firefox: The BigNumber values are not serialized to strings when sent to the background,\n * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action\n */\nexport type StartPollingForBridgeTxStatusArgsSerialized = Omit<\n StartPollingForBridgeTxStatusArgs,\n 'quoteResponse'\n> & {\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata;\n};\n\nexport type SourceChainTxMetaId = string;\n\nexport type BridgeStatusControllerState = {\n txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;\n};\n\n// Actions\ntype BridgeStatusControllerAction<\n FunctionName extends keyof BridgeStatusController,\n> = {\n type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeStatusController[FunctionName];\n};\n\nexport type BridgeStatusControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeStatusControllerStartPollingForBridgeTxStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS>;\n\nexport type BridgeStatusControllerWipeBridgeStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.WIPE_BRIDGE_STATUS>;\n\nexport type BridgeStatusControllerResetStateAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESET_STATE>;\n\nexport type BridgeStatusControllerSubmitTxAction =\n BridgeStatusControllerAction<BridgeStatusAction.SUBMIT_TX>;\n\nexport type BridgeStatusControllerRestartPollingForFailedAttemptsAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESTART_POLLING_FOR_FAILED_ATTEMPTS>;\n\nexport type BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction =\n BridgeStatusControllerAction<BridgeStatusAction.GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID>;\n\nexport type BridgeStatusControllerActions =\n | BridgeStatusControllerStartPollingForBridgeTxStatusAction\n | BridgeStatusControllerWipeBridgeStatusAction\n | BridgeStatusControllerResetStateAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction\n | BridgeStatusControllerRestartPollingForFailedAttemptsAction\n | BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction;\n\n// Events\nexport type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\nexport type BridgeStatusControllerEvents =\n BridgeStatusControllerStateChangeEvent;\n\n/**\n * The external actions available to the BridgeStatusController.\n */\ntype AllowedActions =\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | TransactionControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | GetGasFeeState\n | AccountsControllerGetAccountByAddressAction\n | RemoteFeatureFlagControllerGetStateAction;\n\n/**\n * The external events available to the BridgeStatusController.\n */\ntype AllowedEvents =\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionConfirmedEvent;\n\n/**\n * The messenger for the BridgeStatusController.\n */\nexport type BridgeStatusControllerMessenger = RestrictedMessenger<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerActions | AllowedActions,\n BridgeStatusControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsCA,8EAA8E;AAC9E,2BAA2B;AAE3B,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,8BAAd,cAAc,QAGzB;AA0CD,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,qCAAyB,CAAA;IACzB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,wBAAR,QAAQ,QAanB;AA2CD,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,0FAAoE,CAAA;IACpE,6DAAuC,CAAA;IACvC,4CAAsB,CAAA;IACtB,gDAA0B,CAAA;IAC1B,4CAAsB,CAAA;IACtB,6FAAuE,CAAA;IACvE,8FAAwE,CAAA;AAC1E,CAAC,EARW,kBAAkB,kCAAlB,kBAAkB,QAQ7B","sourcesContent":["import type {\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type {\n BridgeBackgroundAction,\n BridgeControllerAction,\n ChainId,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n TransactionControllerGetStateAction,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type { BridgeStatusController } from './bridge-status-controller';\nimport type { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';\nimport type { StatusResponseSchema } from './utils/validators';\n\n// All fields need to be types not interfaces, same with their children fields\n// o/w you get a type error\n\nexport enum BridgeClientId {\n EXTENSION = 'extension',\n MOBILE = 'mobile',\n}\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * These fields are specific to Solana transactions and can likely be infered from TransactionMeta\n *\n * @deprecated these should be removed eventually\n */\nexport type SolanaTransactionMeta = {\n isSolana: boolean;\n isBridgeTx: boolean;\n};\n\nexport type StatusRequest = {\n bridgeId: string; // lifi, socket, squid\n srcTxHash?: string; // lifi, socket, squid, might be undefined for STX\n bridge: string; // lifi, socket, squid\n srcChainId: ChainId; // lifi, socket, squid\n destChainId: ChainId; // lifi, socket, squid\n quote?: Quote; // squid\n refuel?: boolean; // lifi\n};\n\nexport type StatusRequestDto = Omit<\n StatusRequest,\n 'quote' | 'srcChainId' | 'destChainId' | 'refuel'\n> & {\n srcChainId: string; // lifi, socket, squid\n destChainId: string; // lifi, socket, squid\n requestId?: string;\n refuel?: string; // lifi\n};\n\nexport type StatusRequestWithSrcTxHash = StatusRequest & {\n srcTxHash: string;\n};\n\nexport enum BridgeId {\n HOP = 'hop',\n CELER = 'celer',\n CELERCIRCLE = 'celercircle',\n CONNEXT = 'connext',\n POLYGON = 'polygon',\n AVALANCHE = 'avalanche',\n MULTICHAIN = 'multichain',\n AXELAR = 'axelar',\n ACROSS = 'across',\n STARGATE = 'stargate',\n RELAY = 'relay',\n MAYAN = 'mayan',\n}\n\nexport type StatusResponse = Infer<typeof StatusResponseSchema>;\n\nexport type RefuelStatusResponse = object & StatusResponse;\n\nexport type BridgeHistoryItem = {\n txMetaId: string; // Need this to handle STX that might not have a txHash immediately\n batchId?: string;\n quote: Quote;\n status: StatusResponse;\n startTime?: number; // timestamp in ms\n estimatedProcessingTimeInSeconds: number;\n slippagePercentage: number;\n completionTime?: number; // timestamp in ms\n pricingData?: {\n /**\n * The actual amount sent by user in non-atomic decimal form\n */\n amountSent: QuoteMetadata['sentAmount']['amount'];\n amountSentInUsd?: QuoteMetadata['sentAmount']['usd'];\n quotedGasInUsd?: QuoteMetadata['gasFee']['effective']['usd'];\n quotedGasAmount?: QuoteMetadata['gasFee']['effective']['amount'];\n quotedReturnInUsd?: QuoteMetadata['toTokenAmount']['usd'];\n quotedRefuelSrcAmountInUsd?: string;\n quotedRefuelDestAmountInUsd?: string;\n };\n initialDestAssetBalance?: string;\n targetContractAddress?: string;\n account: string;\n hasApprovalTx: boolean;\n approvalTxId?: string;\n isStxEnabled?: boolean;\n /**\n * Attempts tracking for exponential backoff on failed fetches.\n * We track the number of attempts and the last attempt time for each txMetaId that has failed at least once\n */\n attempts?: {\n counter: number;\n lastAttemptTime: number; // timestamp in ms\n };\n};\n\nexport enum BridgeStatusAction {\n START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',\n WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',\n GET_STATE = 'getState',\n RESET_STATE = 'resetState',\n SUBMIT_TX = 'submitTx',\n RESTART_POLLING_FOR_FAILED_ATTEMPTS = 'restartPollingForFailedAttempts',\n GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID = 'getBridgeHistoryItemByTxMetaId',\n}\n\nexport type TokenAmountValuesSerialized = {\n amount: string;\n valueInCurrency: string | null;\n usd: string | null;\n};\n\nexport type QuoteMetadataSerialized = {\n gasFee: TokenAmountValuesSerialized;\n /**\n * The total network fee for the bridge transaction\n * estimatedGasFees + relayerFees\n */\n totalNetworkFee: TokenAmountValuesSerialized;\n /**\n * The total max network fee for the bridge transaction\n * maxGasFees + relayerFees\n */\n totalMaxNetworkFee: TokenAmountValuesSerialized;\n toTokenAmount: TokenAmountValuesSerialized;\n /**\n * The adjusted return for the bridge transaction\n * destTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValuesSerialized, 'amount'>;\n /**\n * The actual amount sent by user in non-atomic decimal form\n * srcTokenAmount + metabridgeFee\n */\n sentAmount: TokenAmountValuesSerialized;\n swapRate: string; // destTokenAmount / sentAmount\n /**\n * The cost of the bridge transaction\n * sentAmount - adjustedReturn\n */\n cost: Omit<TokenAmountValuesSerialized, 'amount'>;\n};\n\nexport type StartPollingForBridgeTxStatusArgs = {\n bridgeTxMeta: TransactionMeta;\n statusRequest: StatusRequest;\n quoteResponse: QuoteResponse & QuoteMetadata;\n startTime?: BridgeHistoryItem['startTime'];\n slippagePercentage: BridgeHistoryItem['slippagePercentage'];\n initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];\n targetContractAddress?: BridgeHistoryItem['targetContractAddress'];\n approvalTxId?: BridgeHistoryItem['approvalTxId'];\n isStxEnabled?: BridgeHistoryItem['isStxEnabled'];\n accountAddress: string;\n};\n\n/**\n * Chrome: The BigNumber values are automatically serialized to strings when sent to the background\n * Firefox: The BigNumber values are not serialized to strings when sent to the background,\n * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action\n */\nexport type StartPollingForBridgeTxStatusArgsSerialized = Omit<\n StartPollingForBridgeTxStatusArgs,\n 'quoteResponse'\n> & {\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata;\n};\n\nexport type SourceChainTxMetaId = string;\n\nexport type BridgeStatusControllerState = {\n txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;\n};\n\n// Actions\ntype BridgeStatusControllerAction<\n FunctionName extends keyof BridgeStatusController,\n> = {\n type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeStatusController[FunctionName];\n};\n\nexport type BridgeStatusControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeStatusControllerStartPollingForBridgeTxStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS>;\n\nexport type BridgeStatusControllerWipeBridgeStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.WIPE_BRIDGE_STATUS>;\n\nexport type BridgeStatusControllerResetStateAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESET_STATE>;\n\nexport type BridgeStatusControllerSubmitTxAction =\n BridgeStatusControllerAction<BridgeStatusAction.SUBMIT_TX>;\n\nexport type BridgeStatusControllerRestartPollingForFailedAttemptsAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESTART_POLLING_FOR_FAILED_ATTEMPTS>;\n\nexport type BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction =\n BridgeStatusControllerAction<BridgeStatusAction.GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID>;\n\nexport type BridgeStatusControllerActions =\n | BridgeStatusControllerStartPollingForBridgeTxStatusAction\n | BridgeStatusControllerWipeBridgeStatusAction\n | BridgeStatusControllerResetStateAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction\n | BridgeStatusControllerRestartPollingForFailedAttemptsAction\n | BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction;\n\n// Events\nexport type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\nexport type BridgeStatusControllerEvents =\n BridgeStatusControllerStateChangeEvent;\n\n/**\n * The external actions available to the BridgeStatusController.\n */\ntype AllowedActions =\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | TransactionControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | GetGasFeeState\n | AccountsControllerGetAccountByAddressAction\n | RemoteFeatureFlagControllerGetStateAction;\n\n/**\n * The external events available to the BridgeStatusController.\n */\ntype AllowedEvents =\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionConfirmedEvent;\n\n/**\n * The messenger for the BridgeStatusController.\n */\nexport type BridgeStatusControllerMessenger = Messenger<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerActions | AllowedActions,\n BridgeStatusControllerEvents | AllowedEvents\n>;\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AccountsControllerGetAccountByAddressAction, AccountsControllerGetSelectedMultichainAccountAction } from "@metamask/accounts-controller";
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
3
|
import type { BridgeBackgroundAction, BridgeControllerAction, ChainId, Quote, QuoteMetadata, QuoteResponse, TxData } from "@metamask/bridge-controller";
|
|
4
4
|
import type { GetGasFeeState } from "@metamask/gas-fee-controller";
|
|
5
|
+
import type { Messenger } from "@metamask/messenger";
|
|
5
6
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction } from "@metamask/network-controller";
|
|
6
7
|
import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
|
|
7
8
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
|
@@ -187,6 +188,6 @@ type AllowedEvents = TransactionControllerTransactionFailedEvent | TransactionCo
|
|
|
187
188
|
/**
|
|
188
189
|
* The messenger for the BridgeStatusController.
|
|
189
190
|
*/
|
|
190
|
-
export type BridgeStatusControllerMessenger =
|
|
191
|
+
export type BridgeStatusControllerMessenger = Messenger<typeof BRIDGE_STATUS_CONTROLLER_NAME, BridgeStatusControllerActions | AllowedActions, BridgeStatusControllerEvents | AllowedEvents>;
|
|
191
192
|
export {};
|
|
192
193
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2CAA2C,EAC3C,oDAAoD,EACrD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2CAA2C,EAC3C,oDAAoD,EACrD,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,K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EG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,6BAA6B,EACpC,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AccountsControllerGetAccountByAddressAction, AccountsControllerGetSelectedMultichainAccountAction } from "@metamask/accounts-controller";
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
3
|
import type { BridgeBackgroundAction, BridgeControllerAction, ChainId, Quote, QuoteMetadata, QuoteResponse, TxData } from "@metamask/bridge-controller";
|
|
4
4
|
import type { GetGasFeeState } from "@metamask/gas-fee-controller";
|
|
5
|
+
import type { Messenger } from "@metamask/messenger";
|
|
5
6
|
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction } from "@metamask/network-controller";
|
|
6
7
|
import type { RemoteFeatureFlagControllerGetStateAction } from "@metamask/remote-feature-flag-controller";
|
|
7
8
|
import type { HandleSnapRequest } from "@metamask/snaps-controllers";
|
|
@@ -187,6 +188,6 @@ type AllowedEvents = TransactionControllerTransactionFailedEvent | TransactionCo
|
|
|
187
188
|
/**
|
|
188
189
|
* The messenger for the BridgeStatusController.
|
|
189
190
|
*/
|
|
190
|
-
export type BridgeStatusControllerMessenger =
|
|
191
|
+
export type BridgeStatusControllerMessenger = Messenger<typeof BRIDGE_STATUS_CONTROLLER_NAME, BridgeStatusControllerActions | AllowedActions, BridgeStatusControllerEvents | AllowedEvents>;
|
|
191
192
|
export {};
|
|
192
193
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAA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E,8FAAwE,CAAA;AAC1E,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B","sourcesContent":["import type {\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type {\n BridgeBackgroundAction,\n BridgeControllerAction,\n ChainId,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n TransactionControllerGetStateAction,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type { BridgeStatusController } from './bridge-status-controller';\nimport type { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';\nimport type { StatusResponseSchema } from './utils/validators';\n\n// All fields need to be types not interfaces, same with their children fields\n// o/w you get a type error\n\nexport enum BridgeClientId {\n EXTENSION = 'extension',\n MOBILE = 'mobile',\n}\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * These fields are specific to Solana transactions and can likely be infered from TransactionMeta\n *\n * @deprecated these should be removed eventually\n */\nexport type SolanaTransactionMeta = {\n isSolana: boolean;\n isBridgeTx: boolean;\n};\n\nexport type StatusRequest = {\n bridgeId: string; // lifi, socket, squid\n srcTxHash?: string; // lifi, socket, squid, might be undefined for STX\n bridge: string; // lifi, socket, squid\n srcChainId: ChainId; // lifi, socket, squid\n destChainId: ChainId; // lifi, socket, squid\n quote?: Quote; // squid\n refuel?: boolean; // lifi\n};\n\nexport type StatusRequestDto = Omit<\n StatusRequest,\n 'quote' | 'srcChainId' | 'destChainId' | 'refuel'\n> & {\n srcChainId: string; // lifi, socket, squid\n destChainId: string; // lifi, socket, squid\n requestId?: string;\n refuel?: string; // lifi\n};\n\nexport type StatusRequestWithSrcTxHash = StatusRequest & {\n srcTxHash: string;\n};\n\nexport enum BridgeId {\n HOP = 'hop',\n CELER = 'celer',\n CELERCIRCLE = 'celercircle',\n CONNEXT = 'connext',\n POLYGON = 'polygon',\n AVALANCHE = 'avalanche',\n MULTICHAIN = 'multichain',\n AXELAR = 'axelar',\n ACROSS = 'across',\n STARGATE = 'stargate',\n RELAY = 'relay',\n MAYAN = 'mayan',\n}\n\nexport type StatusResponse = Infer<typeof StatusResponseSchema>;\n\nexport type RefuelStatusResponse = object & StatusResponse;\n\nexport type BridgeHistoryItem = {\n txMetaId: string; // Need this to handle STX that might not have a txHash immediately\n batchId?: string;\n quote: Quote;\n status: StatusResponse;\n startTime?: number; // timestamp in ms\n estimatedProcessingTimeInSeconds: number;\n slippagePercentage: number;\n completionTime?: number; // timestamp in ms\n pricingData?: {\n /**\n * The actual amount sent by user in non-atomic decimal form\n */\n amountSent: QuoteMetadata['sentAmount']['amount'];\n amountSentInUsd?: QuoteMetadata['sentAmount']['usd'];\n quotedGasInUsd?: QuoteMetadata['gasFee']['effective']['usd'];\n quotedGasAmount?: QuoteMetadata['gasFee']['effective']['amount'];\n quotedReturnInUsd?: QuoteMetadata['toTokenAmount']['usd'];\n quotedRefuelSrcAmountInUsd?: string;\n quotedRefuelDestAmountInUsd?: string;\n };\n initialDestAssetBalance?: string;\n targetContractAddress?: string;\n account: string;\n hasApprovalTx: boolean;\n approvalTxId?: string;\n isStxEnabled?: boolean;\n /**\n * Attempts tracking for exponential backoff on failed fetches.\n * We track the number of attempts and the last attempt time for each txMetaId that has failed at least once\n */\n attempts?: {\n counter: number;\n lastAttemptTime: number; // timestamp in ms\n };\n};\n\nexport enum BridgeStatusAction {\n START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',\n WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',\n GET_STATE = 'getState',\n RESET_STATE = 'resetState',\n SUBMIT_TX = 'submitTx',\n RESTART_POLLING_FOR_FAILED_ATTEMPTS = 'restartPollingForFailedAttempts',\n GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID = 'getBridgeHistoryItemByTxMetaId',\n}\n\nexport type TokenAmountValuesSerialized = {\n amount: string;\n valueInCurrency: string | null;\n usd: string | null;\n};\n\nexport type QuoteMetadataSerialized = {\n gasFee: TokenAmountValuesSerialized;\n /**\n * The total network fee for the bridge transaction\n * estimatedGasFees + relayerFees\n */\n totalNetworkFee: TokenAmountValuesSerialized;\n /**\n * The total max network fee for the bridge transaction\n * maxGasFees + relayerFees\n */\n totalMaxNetworkFee: TokenAmountValuesSerialized;\n toTokenAmount: TokenAmountValuesSerialized;\n /**\n * The adjusted return for the bridge transaction\n * destTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValuesSerialized, 'amount'>;\n /**\n * The actual amount sent by user in non-atomic decimal form\n * srcTokenAmount + metabridgeFee\n */\n sentAmount: TokenAmountValuesSerialized;\n swapRate: string; // destTokenAmount / sentAmount\n /**\n * The cost of the bridge transaction\n * sentAmount - adjustedReturn\n */\n cost: Omit<TokenAmountValuesSerialized, 'amount'>;\n};\n\nexport type StartPollingForBridgeTxStatusArgs = {\n bridgeTxMeta: TransactionMeta;\n statusRequest: StatusRequest;\n quoteResponse: QuoteResponse & QuoteMetadata;\n startTime?: BridgeHistoryItem['startTime'];\n slippagePercentage: BridgeHistoryItem['slippagePercentage'];\n initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];\n targetContractAddress?: BridgeHistoryItem['targetContractAddress'];\n approvalTxId?: BridgeHistoryItem['approvalTxId'];\n isStxEnabled?: BridgeHistoryItem['isStxEnabled'];\n accountAddress: string;\n};\n\n/**\n * Chrome: The BigNumber values are automatically serialized to strings when sent to the background\n * Firefox: The BigNumber values are not serialized to strings when sent to the background,\n * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action\n */\nexport type StartPollingForBridgeTxStatusArgsSerialized = Omit<\n StartPollingForBridgeTxStatusArgs,\n 'quoteResponse'\n> & {\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata;\n};\n\nexport type SourceChainTxMetaId = string;\n\nexport type BridgeStatusControllerState = {\n txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;\n};\n\n// Actions\ntype BridgeStatusControllerAction<\n FunctionName extends keyof BridgeStatusController,\n> = {\n type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeStatusController[FunctionName];\n};\n\nexport type BridgeStatusControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeStatusControllerStartPollingForBridgeTxStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS>;\n\nexport type BridgeStatusControllerWipeBridgeStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.WIPE_BRIDGE_STATUS>;\n\nexport type BridgeStatusControllerResetStateAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESET_STATE>;\n\nexport type BridgeStatusControllerSubmitTxAction =\n BridgeStatusControllerAction<BridgeStatusAction.SUBMIT_TX>;\n\nexport type BridgeStatusControllerRestartPollingForFailedAttemptsAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESTART_POLLING_FOR_FAILED_ATTEMPTS>;\n\nexport type BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction =\n BridgeStatusControllerAction<BridgeStatusAction.GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID>;\n\nexport type BridgeStatusControllerActions =\n | BridgeStatusControllerStartPollingForBridgeTxStatusAction\n | BridgeStatusControllerWipeBridgeStatusAction\n | BridgeStatusControllerResetStateAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction\n | BridgeStatusControllerRestartPollingForFailedAttemptsAction\n | BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction;\n\n// Events\nexport type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\nexport type BridgeStatusControllerEvents =\n BridgeStatusControllerStateChangeEvent;\n\n/**\n * The external actions available to the BridgeStatusController.\n */\ntype AllowedActions =\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | TransactionControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | GetGasFeeState\n | AccountsControllerGetAccountByAddressAction\n | RemoteFeatureFlagControllerGetStateAction;\n\n/**\n * The external events available to the BridgeStatusController.\n */\ntype AllowedEvents =\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionConfirmedEvent;\n\n/**\n * The messenger for the BridgeStatusController.\n */\nexport type BridgeStatusControllerMessenger = RestrictedMessenger<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerActions | AllowedActions,\n BridgeStatusControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsCA,8EAA8E;AAC9E,2BAA2B;AAE3B,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AA0CD,MAAM,CAAN,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,uCAA2B,CAAA;IAC3B,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,mCAAuB,CAAA;IACvB,qCAAyB,CAAA;IACzB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,KAAR,QAAQ,QAanB;AA2CD,MAAM,CAAN,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,0FAAoE,CAAA;IACpE,6DAAuC,CAAA;IACvC,4CAAsB,CAAA;IACtB,gDAA0B,CAAA;IAC1B,4CAAsB,CAAA;IACtB,6FAAuE,CAAA;IACvE,8FAAwE,CAAA;AAC1E,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B","sourcesContent":["import type {\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type {\n BridgeBackgroundAction,\n BridgeControllerAction,\n ChainId,\n Quote,\n QuoteMetadata,\n QuoteResponse,\n TxData,\n} from '@metamask/bridge-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { Infer } from '@metamask/superstruct';\nimport type {\n TransactionControllerGetStateAction,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionMeta,\n} from '@metamask/transaction-controller';\n\nimport type { BridgeStatusController } from './bridge-status-controller';\nimport type { BRIDGE_STATUS_CONTROLLER_NAME } from './constants';\nimport type { StatusResponseSchema } from './utils/validators';\n\n// All fields need to be types not interfaces, same with their children fields\n// o/w you get a type error\n\nexport enum BridgeClientId {\n EXTENSION = 'extension',\n MOBILE = 'mobile',\n}\n\nexport type FetchFunction = (\n input: RequestInfo | URL,\n init?: RequestInit,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n) => Promise<any>;\n\n/**\n * These fields are specific to Solana transactions and can likely be infered from TransactionMeta\n *\n * @deprecated these should be removed eventually\n */\nexport type SolanaTransactionMeta = {\n isSolana: boolean;\n isBridgeTx: boolean;\n};\n\nexport type StatusRequest = {\n bridgeId: string; // lifi, socket, squid\n srcTxHash?: string; // lifi, socket, squid, might be undefined for STX\n bridge: string; // lifi, socket, squid\n srcChainId: ChainId; // lifi, socket, squid\n destChainId: ChainId; // lifi, socket, squid\n quote?: Quote; // squid\n refuel?: boolean; // lifi\n};\n\nexport type StatusRequestDto = Omit<\n StatusRequest,\n 'quote' | 'srcChainId' | 'destChainId' | 'refuel'\n> & {\n srcChainId: string; // lifi, socket, squid\n destChainId: string; // lifi, socket, squid\n requestId?: string;\n refuel?: string; // lifi\n};\n\nexport type StatusRequestWithSrcTxHash = StatusRequest & {\n srcTxHash: string;\n};\n\nexport enum BridgeId {\n HOP = 'hop',\n CELER = 'celer',\n CELERCIRCLE = 'celercircle',\n CONNEXT = 'connext',\n POLYGON = 'polygon',\n AVALANCHE = 'avalanche',\n MULTICHAIN = 'multichain',\n AXELAR = 'axelar',\n ACROSS = 'across',\n STARGATE = 'stargate',\n RELAY = 'relay',\n MAYAN = 'mayan',\n}\n\nexport type StatusResponse = Infer<typeof StatusResponseSchema>;\n\nexport type RefuelStatusResponse = object & StatusResponse;\n\nexport type BridgeHistoryItem = {\n txMetaId: string; // Need this to handle STX that might not have a txHash immediately\n batchId?: string;\n quote: Quote;\n status: StatusResponse;\n startTime?: number; // timestamp in ms\n estimatedProcessingTimeInSeconds: number;\n slippagePercentage: number;\n completionTime?: number; // timestamp in ms\n pricingData?: {\n /**\n * The actual amount sent by user in non-atomic decimal form\n */\n amountSent: QuoteMetadata['sentAmount']['amount'];\n amountSentInUsd?: QuoteMetadata['sentAmount']['usd'];\n quotedGasInUsd?: QuoteMetadata['gasFee']['effective']['usd'];\n quotedGasAmount?: QuoteMetadata['gasFee']['effective']['amount'];\n quotedReturnInUsd?: QuoteMetadata['toTokenAmount']['usd'];\n quotedRefuelSrcAmountInUsd?: string;\n quotedRefuelDestAmountInUsd?: string;\n };\n initialDestAssetBalance?: string;\n targetContractAddress?: string;\n account: string;\n hasApprovalTx: boolean;\n approvalTxId?: string;\n isStxEnabled?: boolean;\n /**\n * Attempts tracking for exponential backoff on failed fetches.\n * We track the number of attempts and the last attempt time for each txMetaId that has failed at least once\n */\n attempts?: {\n counter: number;\n lastAttemptTime: number; // timestamp in ms\n };\n};\n\nexport enum BridgeStatusAction {\n START_POLLING_FOR_BRIDGE_TX_STATUS = 'startPollingForBridgeTxStatus',\n WIPE_BRIDGE_STATUS = 'wipeBridgeStatus',\n GET_STATE = 'getState',\n RESET_STATE = 'resetState',\n SUBMIT_TX = 'submitTx',\n RESTART_POLLING_FOR_FAILED_ATTEMPTS = 'restartPollingForFailedAttempts',\n GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID = 'getBridgeHistoryItemByTxMetaId',\n}\n\nexport type TokenAmountValuesSerialized = {\n amount: string;\n valueInCurrency: string | null;\n usd: string | null;\n};\n\nexport type QuoteMetadataSerialized = {\n gasFee: TokenAmountValuesSerialized;\n /**\n * The total network fee for the bridge transaction\n * estimatedGasFees + relayerFees\n */\n totalNetworkFee: TokenAmountValuesSerialized;\n /**\n * The total max network fee for the bridge transaction\n * maxGasFees + relayerFees\n */\n totalMaxNetworkFee: TokenAmountValuesSerialized;\n toTokenAmount: TokenAmountValuesSerialized;\n /**\n * The adjusted return for the bridge transaction\n * destTokenAmount - totalNetworkFee\n */\n adjustedReturn: Omit<TokenAmountValuesSerialized, 'amount'>;\n /**\n * The actual amount sent by user in non-atomic decimal form\n * srcTokenAmount + metabridgeFee\n */\n sentAmount: TokenAmountValuesSerialized;\n swapRate: string; // destTokenAmount / sentAmount\n /**\n * The cost of the bridge transaction\n * sentAmount - adjustedReturn\n */\n cost: Omit<TokenAmountValuesSerialized, 'amount'>;\n};\n\nexport type StartPollingForBridgeTxStatusArgs = {\n bridgeTxMeta: TransactionMeta;\n statusRequest: StatusRequest;\n quoteResponse: QuoteResponse & QuoteMetadata;\n startTime?: BridgeHistoryItem['startTime'];\n slippagePercentage: BridgeHistoryItem['slippagePercentage'];\n initialDestAssetBalance?: BridgeHistoryItem['initialDestAssetBalance'];\n targetContractAddress?: BridgeHistoryItem['targetContractAddress'];\n approvalTxId?: BridgeHistoryItem['approvalTxId'];\n isStxEnabled?: BridgeHistoryItem['isStxEnabled'];\n accountAddress: string;\n};\n\n/**\n * Chrome: The BigNumber values are automatically serialized to strings when sent to the background\n * Firefox: The BigNumber values are not serialized to strings when sent to the background,\n * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action\n */\nexport type StartPollingForBridgeTxStatusArgsSerialized = Omit<\n StartPollingForBridgeTxStatusArgs,\n 'quoteResponse'\n> & {\n quoteResponse: QuoteResponse<string | TxData> & QuoteMetadata;\n};\n\nexport type SourceChainTxMetaId = string;\n\nexport type BridgeStatusControllerState = {\n txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>;\n};\n\n// Actions\ntype BridgeStatusControllerAction<\n FunctionName extends keyof BridgeStatusController,\n> = {\n type: `${typeof BRIDGE_STATUS_CONTROLLER_NAME}:${FunctionName}`;\n handler: BridgeStatusController[FunctionName];\n};\n\nexport type BridgeStatusControllerGetStateAction = ControllerGetStateAction<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\n// Maps to BridgeController function names\nexport type BridgeStatusControllerStartPollingForBridgeTxStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS>;\n\nexport type BridgeStatusControllerWipeBridgeStatusAction =\n BridgeStatusControllerAction<BridgeStatusAction.WIPE_BRIDGE_STATUS>;\n\nexport type BridgeStatusControllerResetStateAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESET_STATE>;\n\nexport type BridgeStatusControllerSubmitTxAction =\n BridgeStatusControllerAction<BridgeStatusAction.SUBMIT_TX>;\n\nexport type BridgeStatusControllerRestartPollingForFailedAttemptsAction =\n BridgeStatusControllerAction<BridgeStatusAction.RESTART_POLLING_FOR_FAILED_ATTEMPTS>;\n\nexport type BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction =\n BridgeStatusControllerAction<BridgeStatusAction.GET_BRIDGE_HISTORY_ITEM_BY_TX_META_ID>;\n\nexport type BridgeStatusControllerActions =\n | BridgeStatusControllerStartPollingForBridgeTxStatusAction\n | BridgeStatusControllerWipeBridgeStatusAction\n | BridgeStatusControllerResetStateAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction\n | BridgeStatusControllerRestartPollingForFailedAttemptsAction\n | BridgeStatusControllerGetBridgeHistoryItemByTxMetaIdAction;\n\n// Events\nexport type BridgeStatusControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerState\n>;\n\nexport type BridgeStatusControllerEvents =\n BridgeStatusControllerStateChangeEvent;\n\n/**\n * The external actions available to the BridgeStatusController.\n */\ntype AllowedActions =\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetStateAction\n | NetworkControllerGetNetworkClientByIdAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | HandleSnapRequest\n | TransactionControllerGetStateAction\n | BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>\n | BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>\n | BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>\n | GetGasFeeState\n | AccountsControllerGetAccountByAddressAction\n | RemoteFeatureFlagControllerGetStateAction;\n\n/**\n * The external events available to the BridgeStatusController.\n */\ntype AllowedEvents =\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionConfirmedEvent;\n\n/**\n * The messenger for the BridgeStatusController.\n */\nexport type BridgeStatusControllerMessenger = Messenger<\n typeof BRIDGE_STATUS_CONTROLLER_NAME,\n BridgeStatusControllerActions | AllowedActions,\n BridgeStatusControllerEvents | AllowedEvents\n>;\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findAndUpdateTransactionsInBatch = exports.getAddTransactionBatchParams = exports.toBatchTxParams = exports.getClientRequest = exports.handleMobileHardwareWalletDelay = exports.handleApprovalDelay = exports.
|
|
3
|
+
exports.findAndUpdateTransactionsInBatch = exports.getAddTransactionBatchParams = exports.toBatchTxParams = exports.getClientRequest = exports.handleMobileHardwareWalletDelay = exports.handleApprovalDelay = exports.handleSolanaTxResponse = exports.getTxMetaFields = exports.getStatusRequestParams = exports.getUSDTAllowanceResetTx = exports.generateActionId = void 0;
|
|
4
4
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
5
5
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
6
|
+
const keyring_api_1 = require("@metamask/keyring-api");
|
|
6
7
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
7
8
|
const utils_1 = require("@metamask/utils");
|
|
8
9
|
const bignumber_js_1 = require("bignumber.js");
|
|
9
10
|
const uuid_1 = require("uuid");
|
|
10
11
|
const gas_1 = require("./gas.cjs");
|
|
11
|
-
const snaps_1 = require("./snaps.cjs");
|
|
12
12
|
const constants_1 = require("../constants.cjs");
|
|
13
13
|
const generateActionId = () => (Date.now() + Math.random()).toString();
|
|
14
14
|
exports.generateActionId = generateActionId;
|
|
@@ -37,17 +37,8 @@ const getStatusRequestParams = (quoteResponse) => {
|
|
|
37
37
|
};
|
|
38
38
|
exports.getStatusRequestParams = getStatusRequestParams;
|
|
39
39
|
const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
|
40
|
-
// Handle destination chain ID - should always be convertible for EVM destinations
|
|
41
|
-
let destinationChainId;
|
|
42
|
-
try {
|
|
43
|
-
destinationChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.destChainId);
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// Fallback for non-EVM destination (shouldn't happen for BTC->EVM)
|
|
47
|
-
destinationChainId = '0x1'; // Default to mainnet
|
|
48
|
-
}
|
|
49
40
|
return {
|
|
50
|
-
destinationChainId,
|
|
41
|
+
destinationChainId: (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.destChainId),
|
|
51
42
|
sourceTokenAmount: quoteResponse.quote.srcTokenAmount,
|
|
52
43
|
sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,
|
|
53
44
|
sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,
|
|
@@ -56,24 +47,14 @@ const getTxMetaFields = (quoteResponse, approvalTxId) => {
|
|
|
56
47
|
destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,
|
|
57
48
|
destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,
|
|
58
49
|
destinationTokenAddress: quoteResponse.quote.destAsset.address,
|
|
59
|
-
|
|
50
|
+
chainId: (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId),
|
|
60
51
|
approvalTxId,
|
|
61
52
|
// this is the decimal (non atomic) amount (not USD value) of source token to swap
|
|
62
53
|
swapTokenValue: quoteResponse.sentAmount.amount,
|
|
63
54
|
};
|
|
64
55
|
};
|
|
65
56
|
exports.getTxMetaFields = getTxMetaFields;
|
|
66
|
-
|
|
67
|
-
* Handles the response from non-EVM transaction submission
|
|
68
|
-
* Works with the new unified ClientRequest:signAndSendTransaction interface
|
|
69
|
-
* Supports Solana, Bitcoin, and other non-EVM chains
|
|
70
|
-
*
|
|
71
|
-
* @param snapResponse - The response from the snap after transaction submission
|
|
72
|
-
* @param quoteResponse - The quote response containing trade details and metadata
|
|
73
|
-
* @param selectedAccount - The selected account information
|
|
74
|
-
* @returns The transaction metadata including non-EVM specific fields
|
|
75
|
-
*/
|
|
76
|
-
const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
|
57
|
+
const handleSolanaTxResponse = (snapResponse, quoteResponse, selectedAccount) => {
|
|
77
58
|
const selectedAccountAddress = selectedAccount.address;
|
|
78
59
|
const snapId = selectedAccount.metadata.snap?.id;
|
|
79
60
|
let hash;
|
|
@@ -82,11 +63,9 @@ const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) =>
|
|
|
82
63
|
hash = snapResponse;
|
|
83
64
|
}
|
|
84
65
|
else if (snapResponse && typeof snapResponse === 'object') {
|
|
85
|
-
//
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
else if ('result' in snapResponse &&
|
|
66
|
+
// If it's an object with result property, try to get the signature
|
|
67
|
+
if (typeof snapResponse === 'object' &&
|
|
68
|
+
'result' in snapResponse &&
|
|
90
69
|
snapResponse.result &&
|
|
91
70
|
typeof snapResponse.result === 'object') {
|
|
92
71
|
// Try to extract signature from common locations in response object
|
|
@@ -96,26 +75,15 @@ const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) =>
|
|
|
96
75
|
snapResponse.result.hash ||
|
|
97
76
|
snapResponse.result.txHash;
|
|
98
77
|
}
|
|
99
|
-
|
|
78
|
+
if (typeof snapResponse === 'object' &&
|
|
79
|
+
'signature' in snapResponse &&
|
|
100
80
|
snapResponse.signature &&
|
|
101
81
|
typeof snapResponse.signature === 'string') {
|
|
102
82
|
hash = snapResponse.signature;
|
|
103
83
|
}
|
|
104
84
|
}
|
|
85
|
+
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
|
|
105
86
|
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
106
|
-
let hexChainId;
|
|
107
|
-
try {
|
|
108
|
-
hexChainId = (0, bridge_controller_1.formatChainIdToHex)(quoteResponse.quote.srcChainId);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// TODO: Fix chain ID activity list handling for Bitcoin
|
|
112
|
-
// Fallback to Ethereum mainnet for now
|
|
113
|
-
hexChainId = '0x1';
|
|
114
|
-
}
|
|
115
|
-
// Extract the transaction data for storage
|
|
116
|
-
const tradeData = typeof quoteResponse.trade === 'string'
|
|
117
|
-
? quoteResponse.trade
|
|
118
|
-
: quoteResponse.trade.unsignedPsbtBase64;
|
|
119
87
|
// Create a transaction meta object with bridge-specific fields
|
|
120
88
|
return {
|
|
121
89
|
...(0, exports.getTxMetaFields)(quoteResponse),
|
|
@@ -123,17 +91,17 @@ const handleNonEvmTxResponse = (snapResponse, quoteResponse, selectedAccount) =>
|
|
|
123
91
|
id: hash ?? (0, uuid_1.v4)(),
|
|
124
92
|
chainId: hexChainId,
|
|
125
93
|
networkClientId: snapId ?? hexChainId,
|
|
126
|
-
txParams: { from: selectedAccountAddress, data:
|
|
94
|
+
txParams: { from: selectedAccountAddress, data: quoteResponse.trade },
|
|
127
95
|
type: isBridgeTx ? transaction_controller_1.TransactionType.bridge : transaction_controller_1.TransactionType.swap,
|
|
128
96
|
status: transaction_controller_1.TransactionStatus.submitted,
|
|
129
97
|
hash,
|
|
130
98
|
origin: snapId,
|
|
131
|
-
// Add an explicit flag to mark this as a
|
|
99
|
+
// Add an explicit bridge flag to mark this as a Solana transaction
|
|
132
100
|
isSolana: true,
|
|
133
101
|
isBridgeTx,
|
|
134
102
|
};
|
|
135
103
|
};
|
|
136
|
-
exports.
|
|
104
|
+
exports.handleSolanaTxResponse = handleSolanaTxResponse;
|
|
137
105
|
const handleApprovalDelay = async (quoteResponse) => {
|
|
138
106
|
if ([bridge_controller_1.ChainId.LINEA, bridge_controller_1.ChainId.BASE].includes(quoteResponse.quote.srcChainId)) {
|
|
139
107
|
const debugLog = (0, utils_1.createProjectLogger)('bridge');
|
|
@@ -157,22 +125,23 @@ const handleMobileHardwareWalletDelay = async (requireApproval) => {
|
|
|
157
125
|
}
|
|
158
126
|
};
|
|
159
127
|
exports.handleMobileHardwareWalletDelay = handleMobileHardwareWalletDelay;
|
|
160
|
-
/**
|
|
161
|
-
* Creates a request to sign and send a transaction for non-EVM chains
|
|
162
|
-
* Uses the new unified ClientRequest:signAndSendTransaction interface
|
|
163
|
-
*
|
|
164
|
-
* @param quoteResponse - The quote response containing trade details and metadata
|
|
165
|
-
* @param selectedAccount - The selected account information
|
|
166
|
-
* @returns The snap request object for signing and sending transaction
|
|
167
|
-
*/
|
|
168
128
|
const getClientRequest = (quoteResponse, selectedAccount) => {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
:
|
|
174
|
-
|
|
175
|
-
|
|
129
|
+
const clientReqId = (0, uuid_1.v4)();
|
|
130
|
+
return {
|
|
131
|
+
origin: 'metamask',
|
|
132
|
+
snapId: selectedAccount.metadata.snap?.id,
|
|
133
|
+
handler: 'onClientRequest',
|
|
134
|
+
request: {
|
|
135
|
+
id: clientReqId,
|
|
136
|
+
jsonrpc: '2.0',
|
|
137
|
+
method: 'signAndSendTransactionWithoutConfirmation',
|
|
138
|
+
params: {
|
|
139
|
+
account: { address: selectedAccount.address },
|
|
140
|
+
transaction: quoteResponse.trade,
|
|
141
|
+
scope: keyring_api_1.SolScope.Mainnet,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
176
145
|
};
|
|
177
146
|
exports.getClientRequest = getClientRequest;
|
|
178
147
|
const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, { maxFeePerGas, maxPriorityFeePerGas, gas, }) => {
|
|
@@ -193,20 +162,20 @@ const toBatchTxParams = (disable7702, { chainId, gasLimit, ...trade }, { maxFeeP
|
|
|
193
162
|
};
|
|
194
163
|
};
|
|
195
164
|
exports.toBatchTxParams = toBatchTxParams;
|
|
196
|
-
const getAddTransactionBatchParams = async ({
|
|
165
|
+
const getAddTransactionBatchParams = async ({ messenger, isBridgeTx, approval, resetApproval, trade, quoteResponse: { quote: { feeData: { txFee }, gasIncluded, gasIncluded7702, }, sentAmount, toTokenAmount, }, requireApproval = false, estimateGasFeeFn, }) => {
|
|
197
166
|
const isGasless = gasIncluded || gasIncluded7702;
|
|
198
|
-
const selectedAccount =
|
|
167
|
+
const selectedAccount = messenger.call('AccountsController:getAccountByAddress', trade.from);
|
|
199
168
|
if (!selectedAccount) {
|
|
200
169
|
throw new Error('Failed to submit cross-chain swap batch transaction: unknown account in trade data');
|
|
201
170
|
}
|
|
202
171
|
const hexChainId = (0, bridge_controller_1.formatChainIdToHex)(trade.chainId);
|
|
203
|
-
const networkClientId =
|
|
172
|
+
const networkClientId = messenger.call('NetworkController:findNetworkClientIdByChainId', hexChainId);
|
|
204
173
|
// When an active quote has gasIncluded7702 set to true,
|
|
205
174
|
// enable 7702 gasless txs for smart accounts
|
|
206
175
|
const disable7702 = gasIncluded7702 !== true;
|
|
207
176
|
const transactions = [];
|
|
208
177
|
if (resetApproval) {
|
|
209
|
-
const gasFees = await (0, gas_1.calculateGasFees)(disable7702,
|
|
178
|
+
const gasFees = await (0, gas_1.calculateGasFees)(disable7702, messenger, estimateGasFeeFn, resetApproval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
210
179
|
transactions.push({
|
|
211
180
|
type: isBridgeTx
|
|
212
181
|
? transaction_controller_1.TransactionType.bridgeApproval
|
|
@@ -215,7 +184,7 @@ const getAddTransactionBatchParams = async ({ messagingSystem, isBridgeTx, appro
|
|
|
215
184
|
});
|
|
216
185
|
}
|
|
217
186
|
if (approval) {
|
|
218
|
-
const gasFees = await (0, gas_1.calculateGasFees)(disable7702,
|
|
187
|
+
const gasFees = await (0, gas_1.calculateGasFees)(disable7702, messenger, estimateGasFeeFn, approval, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
219
188
|
transactions.push({
|
|
220
189
|
type: isBridgeTx
|
|
221
190
|
? transaction_controller_1.TransactionType.bridgeApproval
|
|
@@ -223,7 +192,7 @@ const getAddTransactionBatchParams = async ({ messagingSystem, isBridgeTx, appro
|
|
|
223
192
|
params: (0, exports.toBatchTxParams)(disable7702, approval, gasFees),
|
|
224
193
|
});
|
|
225
194
|
}
|
|
226
|
-
const gasFees = await (0, gas_1.calculateGasFees)(disable7702,
|
|
195
|
+
const gasFees = await (0, gas_1.calculateGasFees)(disable7702, messenger, estimateGasFeeFn, trade, networkClientId, hexChainId, isGasless ? txFee : undefined);
|
|
227
196
|
transactions.push({
|
|
228
197
|
type: isBridgeTx ? transaction_controller_1.TransactionType.bridge : transaction_controller_1.TransactionType.swap,
|
|
229
198
|
params: (0, exports.toBatchTxParams)(disable7702, trade, gasFees),
|
|
@@ -244,8 +213,8 @@ const getAddTransactionBatchParams = async ({ messagingSystem, isBridgeTx, appro
|
|
|
244
213
|
return transactionParams;
|
|
245
214
|
};
|
|
246
215
|
exports.getAddTransactionBatchParams = getAddTransactionBatchParams;
|
|
247
|
-
const findAndUpdateTransactionsInBatch = ({
|
|
248
|
-
const txs =
|
|
216
|
+
const findAndUpdateTransactionsInBatch = ({ messenger, updateTransactionFn, batchId, txDataByType, }) => {
|
|
217
|
+
const txs = messenger.call('TransactionController:getState').transactions;
|
|
249
218
|
const txBatch = {
|
|
250
219
|
approvalMeta: undefined,
|
|
251
220
|
tradeMeta: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,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DAA+D;gBAC/D,IACE,MAAM,KAAK,wCAAe,CAAC,IAAI;oBAC/B,EAAE,CAAC,IAAI,KAAK,wCAAe,CAAC,KAAK,EACjC;oBACA,OAAO,IAAI,CAAC;iBACb;gBACD,sDAAsD;gBACtD,IACE,MAAM,KAAK,wCAAe,CAAC,YAAY;oBACvC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,EAC3B;oBACA,OAAO,IAAI,CAAC;iBACb;aACF;YAED,mDAAmD;YACnD,OAAO,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,EAAE;YACV,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAyB,EAAE,CAAC;YACjE,mBAAmB,CAAC,SAAS,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAC;YAC9D,OAAO,CACL,CAAC,wCAAe,CAAC,cAAc,EAAE,wCAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;SACf;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AA1EW,QAAA,gCAAgC,oCA0E3C","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n ChainId,\n formatChainIdToCaip,\n formatChainIdToHex,\n getEthUsdtResetData,\n isCrossChain,\n isEthUsdt,\n type QuoteMetadata,\n type QuoteResponse,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n BatchTransactionParams,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport { createClientTransactionRequest } from './snaps';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getUSDTAllowanceResetTx = async (\n messagingSystem: BridgeStatusControllerMessenger,\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n) => {\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n if (\n quoteResponse.approval &&\n isEthUsdt(hexChainId, quoteResponse.quote.srcAsset.address)\n ) {\n const allowance = new BigNumber(\n await messagingSystem.call(\n 'BridgeController:getBridgeERC20Allowance',\n quoteResponse.quote.srcAsset.address,\n hexChainId,\n ),\n );\n const shouldResetApproval =\n allowance.lt(quoteResponse.sentAmount.amount) && allowance.gt(0);\n if (shouldResetApproval) {\n return { ...quoteResponse.approval, data: getEthUsdtResetData() };\n }\n }\n return undefined;\n};\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' | 'chainId'\n> => {\n // Handle destination chain ID - should always be convertible for EVM destinations\n let destinationChainId;\n try {\n destinationChainId = formatChainIdToHex(quoteResponse.quote.destChainId);\n } catch {\n // Fallback for non-EVM destination (shouldn't happen for BTC->EVM)\n destinationChainId = '0x1' as `0x${string}`; // Default to mainnet\n }\n\n return {\n destinationChainId,\n sourceTokenAmount: quoteResponse.quote.srcTokenAmount,\n sourceTokenSymbol: quoteResponse.quote.srcAsset.symbol,\n sourceTokenDecimals: quoteResponse.quote.srcAsset.decimals,\n sourceTokenAddress: quoteResponse.quote.srcAsset.address,\n\n destinationTokenAmount: quoteResponse.quote.destTokenAmount,\n destinationTokenSymbol: quoteResponse.quote.destAsset.symbol,\n destinationTokenDecimals: quoteResponse.quote.destAsset.decimals,\n destinationTokenAddress: quoteResponse.quote.destAsset.address,\n\n // chainId is now excluded from this function and handled by the caller\n approvalTxId,\n // this is the decimal (non atomic) amount (not USD value) of source token to swap\n swapTokenValue: quoteResponse.sentAmount.amount,\n };\n};\n\n/**\n * Handles the response from non-EVM transaction submission\n * Works with the new unified ClientRequest:signAndSendTransaction interface\n * Supports Solana, Bitcoin, and other non-EVM chains\n *\n * @param snapResponse - The response from the snap after transaction submission\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The transaction metadata including non-EVM specific fields\n */\nexport const handleNonEvmTxResponse = (\n snapResponse:\n | string\n | { transactionId: string } // New unified interface response\n | { result: Record<string, string> }\n | { signature: string },\n quoteResponse: Omit<\n QuoteResponse<string | { unsignedPsbtBase64: string }>,\n 'approval'\n > &\n QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n): TransactionMeta & SolanaTransactionMeta => {\n const selectedAccountAddress = selectedAccount.address;\n const snapId = selectedAccount.metadata.snap?.id;\n let hash;\n // Handle different response formats\n if (typeof snapResponse === 'string') {\n hash = snapResponse;\n } else if (snapResponse && typeof snapResponse === 'object') {\n // Check for new unified interface response format first\n if ('transactionId' in snapResponse && snapResponse.transactionId) {\n hash = snapResponse.transactionId;\n } else if (\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n } else if (\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n let hexChainId;\n try {\n hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n } catch {\n // TODO: Fix chain ID activity list handling for Bitcoin\n // Fallback to Ethereum mainnet for now\n hexChainId = '0x1' as `0x${string}`;\n }\n\n // Extract the transaction data for storage\n const tradeData =\n typeof quoteResponse.trade === 'string'\n ? quoteResponse.trade\n : quoteResponse.trade.unsignedPsbtBase64;\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: tradeData },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit flag to mark this as a non-EVM transaction\n isSolana: true, // TODO deprecate this and use chainId to detect non-EVM chains\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n quoteResponse: QuoteResponse<TxData | string>,\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(quoteResponse.quote.srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\n/**\n * Creates a request to sign and send a transaction for non-EVM chains\n * Uses the new unified ClientRequest:signAndSendTransaction interface\n *\n * @param quoteResponse - The quote response containing trade details and metadata\n * @param selectedAccount - The selected account information\n * @returns The snap request object for signing and sending transaction\n */\nexport const getClientRequest = (\n quoteResponse: Omit<\n QuoteResponse<string | { unsignedPsbtBase64: string }>,\n 'approval'\n > &\n QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const scope = formatChainIdToCaip(quoteResponse.quote.srcChainId);\n\n // Extract the transaction data - Bitcoin uses unsignedPsbtBase64, others use string\n const transactionData =\n typeof quoteResponse.trade === 'string'\n ? quoteResponse.trade\n : quoteResponse.trade.unsignedPsbtBase64;\n\n // Use the new unified interface\n return createClientTransactionRequest(\n selectedAccount.metadata.snap?.id as string,\n transactionData,\n scope,\n selectedAccount.id,\n );\n};\n\nexport const toBatchTxParams = (\n disable7702: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (!disable7702) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messagingSystem,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n estimateGasFeeFn,\n}: {\n messagingSystem: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messagingSystem.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messagingSystem.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // When an active quote has gasIncluded7702 set to true,\n // enable 7702 gasless txs for smart accounts\n const disable7702 = gasIncluded7702 !== true;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messagingSystem,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messagingSystem,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n disable7702,\n messagingSystem,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(disable7702, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messagingSystem,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messagingSystem: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messagingSystem.call(\n 'TransactionController:getState',\n ).transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n txType === TransactionType.swap &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n txType === TransactionType.swapApproval &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAEA,mEAQqC;AACrC,iEAAmD;AACnD,uDAAiD;AAKjD,6EAI0C;AAC1C,2CAAsD;AACtD,+CAAyC;AACzC,+BAAkC;AAElC,mCAAyC;AAEzC,gDAAiD;AAM1C,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,uBAAuB,GAAG,KAAK,EAC1C,eAAgD,EAChD,aAA6D,EAC7D,EAAE;IACF,MAAM,UAAU,GAAG,IAAA,sCAAkB,EAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACtE,IACE,aAAa,CAAC,QAAQ;QACtB,IAAA,6BAAS,EAAC,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAC3D;QACA,MAAM,SAAS,GAAG,IAAI,wBAAS,CAC7B,MAAM,eAAe,CAAC,IAAI,CACxB,0CAA0C,EAC1C,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EACpC,UAAU,CACX,CACF,CAAC;QACF,MAAM,mBAAmB,GACvB,SAAS,CAAC,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACnE,IAAI,mBAAmB,EAAE;YACvB,OAAO,EAAE,GAAG,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAA,uCAAmB,GAAE,EAAE,CAAC;SACnE;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAvBW,QAAA,uBAAuB,2BAu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CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,EAAE;YACV,MAAM,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAyB,EAAE,CAAC;YACjE,mBAAmB,CAAC,SAAS,EAAE,qBAAqB,MAAM,EAAE,CAAC,CAAC;YAC9D,OAAO,CACL,CAAC,wCAAe,CAAC,cAAc,EAAE,wCAAe,CAAC,YAAY,CAAC,CAAC,QAAQ,CACrE,MAAyB,CAC1B;gBACC,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,WAAW,CAChB,GAAG,SAAS,CAAC;SACf;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAxEW,QAAA,gCAAgC,oCAwE3C","sourcesContent":["import type { AccountsControllerState } from '@metamask/accounts-controller';\nimport type { TxData } from '@metamask/bridge-controller';\nimport {\n ChainId,\n formatChainIdToHex,\n getEthUsdtResetData,\n isCrossChain,\n isEthUsdt,\n type QuoteMetadata,\n type QuoteResponse,\n} from '@metamask/bridge-controller';\nimport { toHex } from '@metamask/controller-utils';\nimport { SolScope } from '@metamask/keyring-api';\nimport type {\n BatchTransactionParams,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n type TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { createProjectLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { v4 as uuid } from 'uuid';\n\nimport { calculateGasFees } from './gas';\nimport type { TransactionBatchSingleRequest } from '../../../transaction-controller/src/types';\nimport { APPROVAL_DELAY_MS } from '../constants';\nimport type {\n BridgeStatusControllerMessenger,\n SolanaTransactionMeta,\n} from '../types';\n\nexport const generateActionId = () => (Date.now() + Math.random()).toString();\n\nexport const getUSDTAllowanceResetTx = async (\n messagingSystem: BridgeStatusControllerMessenger,\n quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,\n) => {\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n if (\n quoteResponse.approval &&\n isEthUsdt(hexChainId, quoteResponse.quote.srcAsset.address)\n ) {\n const allowance = new BigNumber(\n await messagingSystem.call(\n 'BridgeController:getBridgeERC20Allowance',\n quoteResponse.quote.srcAsset.address,\n hexChainId,\n ),\n );\n const shouldResetApproval =\n allowance.lt(quoteResponse.sentAmount.amount) && allowance.gt(0);\n if (shouldResetApproval) {\n return { ...quoteResponse.approval, data: getEthUsdtResetData() };\n }\n }\n return undefined;\n};\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:\n | string\n | { result: Record<string, string> }\n | { signature: 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 (\n typeof snapResponse === 'object' &&\n 'result' in snapResponse &&\n snapResponse.result &&\n typeof snapResponse.result === 'object'\n ) {\n // Try to extract signature from common locations in response object\n hash =\n snapResponse.result.signature ||\n snapResponse.result.txid ||\n snapResponse.result.hash ||\n snapResponse.result.txHash;\n }\n if (\n typeof snapResponse === 'object' &&\n 'signature' in snapResponse &&\n snapResponse.signature &&\n typeof snapResponse.signature === 'string'\n ) {\n hash = snapResponse.signature;\n }\n }\n\n const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);\n const isBridgeTx = isCrossChain(\n quoteResponse.quote.srcChainId,\n quoteResponse.quote.destChainId,\n );\n\n // Create a transaction meta object with bridge-specific fields\n return {\n ...getTxMetaFields(quoteResponse),\n time: Date.now(),\n id: hash ?? uuid(),\n chainId: hexChainId,\n networkClientId: snapId ?? hexChainId,\n txParams: { from: selectedAccountAddress, data: quoteResponse.trade },\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n status: TransactionStatus.submitted,\n hash, // Add the transaction signature as hash\n origin: snapId,\n // Add an explicit bridge flag to mark this as a Solana transaction\n isSolana: true, // TODO deprecate this and use chainId\n isBridgeTx,\n };\n};\n\nexport const handleApprovalDelay = async (\n quoteResponse: QuoteResponse<TxData | string>,\n) => {\n if ([ChainId.LINEA, ChainId.BASE].includes(quoteResponse.quote.srcChainId)) {\n const debugLog = createProjectLogger('bridge');\n debugLog(\n 'Delaying submitting bridge tx to make Linea and Base confirmation more likely',\n );\n const waitPromise = new Promise((resolve) =>\n setTimeout(resolve, APPROVAL_DELAY_MS),\n );\n await waitPromise;\n }\n};\n\n/**\n * Adds a delay for hardware wallet transactions on mobile to fix an issue\n * where the Ledger does not get prompted for the 2nd approval.\n * Extension does not have this issue.\n *\n * @param requireApproval - Whether the delay should be applied\n */\nexport const handleMobileHardwareWalletDelay = async (\n requireApproval: boolean,\n) => {\n if (requireApproval) {\n const mobileHardwareWalletDelay = new Promise((resolve) =>\n setTimeout(resolve, 1000),\n );\n await mobileHardwareWalletDelay;\n }\n};\n\nexport const getClientRequest = (\n quoteResponse: Omit<QuoteResponse<string>, 'approval'> & QuoteMetadata,\n selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string],\n) => {\n const clientReqId = uuid();\n\n return {\n origin: 'metamask',\n snapId: selectedAccount.metadata.snap?.id as never,\n handler: 'onClientRequest' as never,\n request: {\n id: clientReqId,\n jsonrpc: '2.0',\n method: 'signAndSendTransactionWithoutConfirmation',\n params: {\n account: { address: selectedAccount.address },\n transaction: quoteResponse.trade,\n scope: SolScope.Mainnet,\n },\n },\n };\n};\n\nexport const toBatchTxParams = (\n disable7702: boolean,\n { chainId, gasLimit, ...trade }: TxData,\n {\n maxFeePerGas,\n maxPriorityFeePerGas,\n gas,\n }: { maxFeePerGas?: string; maxPriorityFeePerGas?: string; gas?: string },\n): BatchTransactionParams => {\n const params = {\n ...trade,\n data: trade.data as `0x${string}`,\n to: trade.to as `0x${string}`,\n value: trade.value as `0x${string}`,\n };\n if (!disable7702) {\n return params;\n }\n\n return {\n ...params,\n gas: toHex(gas ?? 0),\n maxFeePerGas: toHex(maxFeePerGas ?? 0),\n maxPriorityFeePerGas: toHex(maxPriorityFeePerGas ?? 0),\n };\n};\n\nexport const getAddTransactionBatchParams = async ({\n messenger,\n isBridgeTx,\n approval,\n resetApproval,\n trade,\n quoteResponse: {\n quote: {\n feeData: { txFee },\n gasIncluded,\n gasIncluded7702,\n },\n sentAmount,\n toTokenAmount,\n },\n requireApproval = false,\n estimateGasFeeFn,\n}: {\n messenger: BridgeStatusControllerMessenger;\n isBridgeTx: boolean;\n trade: TxData;\n quoteResponse: Omit<QuoteResponse, 'approval' | 'trade'> & QuoteMetadata;\n estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;\n approval?: TxData;\n resetApproval?: TxData;\n requireApproval?: boolean;\n}) => {\n const isGasless = gasIncluded || gasIncluded7702;\n const selectedAccount = messenger.call(\n 'AccountsController:getAccountByAddress',\n trade.from,\n );\n if (!selectedAccount) {\n throw new Error(\n 'Failed to submit cross-chain swap batch transaction: unknown account in trade data',\n );\n }\n const hexChainId = formatChainIdToHex(trade.chainId);\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n hexChainId,\n );\n\n // When an active quote has gasIncluded7702 set to true,\n // enable 7702 gasless txs for smart accounts\n const disable7702 = gasIncluded7702 !== true;\n const transactions: TransactionBatchSingleRequest[] = [];\n if (resetApproval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n resetApproval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, resetApproval, gasFees),\n });\n }\n if (approval) {\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n approval,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx\n ? TransactionType.bridgeApproval\n : TransactionType.swapApproval,\n params: toBatchTxParams(disable7702, approval, gasFees),\n });\n }\n const gasFees = await calculateGasFees(\n disable7702,\n messenger,\n estimateGasFeeFn,\n trade,\n networkClientId,\n hexChainId,\n isGasless ? txFee : undefined,\n );\n transactions.push({\n type: isBridgeTx ? TransactionType.bridge : TransactionType.swap,\n params: toBatchTxParams(disable7702, trade, gasFees),\n assetsFiatValues: {\n sending: sentAmount?.valueInCurrency?.toString(),\n receiving: toTokenAmount?.valueInCurrency?.toString(),\n },\n });\n const transactionParams: Parameters<\n TransactionController['addTransactionBatch']\n >[0] = {\n disable7702,\n isGasFeeIncluded: Boolean(gasIncluded7702),\n networkClientId,\n requireApproval,\n origin: 'metamask',\n from: trade.from as `0x${string}`,\n transactions,\n };\n\n return transactionParams;\n};\n\nexport const findAndUpdateTransactionsInBatch = ({\n messenger,\n updateTransactionFn,\n batchId,\n txDataByType,\n}: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n batchId: string;\n txDataByType: { [key in TransactionType]?: string };\n}) => {\n const txs = messenger.call('TransactionController:getState').transactions;\n const txBatch: {\n approvalMeta?: TransactionMeta;\n tradeMeta?: TransactionMeta;\n } = {\n approvalMeta: undefined,\n tradeMeta: undefined,\n };\n\n // This is a workaround to update the tx type after the tx is signed\n // TODO: remove this once the tx type for batch txs is preserved in the tx controller\n Object.entries(txDataByType).forEach(([txType, txData]) => {\n // Find transaction by batchId and either matching data or delegation characteristics\n const txMeta = txs.find((tx) => {\n if (tx.batchId !== batchId) {\n return false;\n }\n\n // For 7702 delegated transactions, check for delegation-specific fields\n // These transactions might have authorizationList or delegationAddress\n const is7702Transaction =\n (Array.isArray(tx.txParams.authorizationList) &&\n tx.txParams.authorizationList.length > 0) ||\n Boolean(tx.delegationAddress);\n\n if (is7702Transaction) {\n // For 7702 transactions, we need to match based on transaction type\n // since the data field might be different (batch execute call)\n if (\n txType === TransactionType.swap &&\n tx.type === TransactionType.batch\n ) {\n return true;\n }\n // Also check if it's an approval transaction for 7702\n if (\n txType === TransactionType.swapApproval &&\n tx.txParams.data === txData\n ) {\n return true;\n }\n }\n\n // Default matching logic for non-7702 transactions\n return tx.txParams.data === txData;\n });\n\n if (txMeta) {\n const updatedTx = { ...txMeta, type: txType as TransactionType };\n updateTransactionFn(updatedTx, `Update tx type to ${txType}`);\n txBatch[\n [TransactionType.bridgeApproval, TransactionType.swapApproval].includes(\n txType as TransactionType,\n )\n ? 'approvalMeta'\n : 'tradeMeta'\n ] = updatedTx;\n }\n });\n\n return txBatch;\n};\n"]}
|