/// import { Hardfork } from '@ethereumjs/common'; import type { TypedTransaction } from '@ethereumjs/tx'; import type { AddApprovalRequest } from '@metamask/approval-controller'; import type { BaseConfig, BaseState, RestrictedControllerMessenger } from '@metamask/base-controller'; import { BaseController } from '@metamask/base-controller'; import type { BlockTracker, NetworkState, Provider } from '@metamask/network-controller'; import { EventEmitter } from 'events'; import type { Transaction, TransactionMeta, WalletDevice } from './types'; export declare const HARDFORK = Hardfork.London; /** * @type Result * @property result - Promise resolving to a new transaction hash * @property transactionMeta - Meta information about this new transaction */ export interface Result { result: Promise; transactionMeta: TransactionMeta; } /** * @type Fetch All Options * @property fromBlock - String containing a specific block decimal number * @property etherscanApiKey - API key to be used to fetch token transactions */ export interface FetchAllOptions { fromBlock?: string; etherscanApiKey?: string; } export interface GasPriceValue { gasPrice: string; } export interface FeeMarketEIP1559Values { maxFeePerGas: string; maxPriorityFeePerGas: string; } /** * @type TransactionConfig * * Transaction controller configuration * @property interval - Polling interval used to fetch new currency rate * @property provider - Provider used to create a new underlying EthQuery instance * @property sign - Method used to sign transactions */ export interface TransactionConfig extends BaseConfig { interval: number; sign?: (transaction: Transaction, from: string) => Promise; txHistoryLimit: number; } /** * @type MethodData * * Method data registry object * @property registryMethod - Registry method raw string * @property parsedRegistryMethod - Registry method object, containing name and method arguments */ export interface MethodData { registryMethod: string; parsedRegistryMethod: Record; } /** * @type TransactionState * * Transaction controller state * @property transactions - A list of TransactionMeta objects * @property methodData - Object containing all known method data information */ export interface TransactionState extends BaseState { transactions: TransactionMeta[]; methodData: { [key: string]: MethodData; }; lastFetchedBlockNumbers: { [key: string]: number; }; } /** * Multiplier used to determine a transaction's increased gas fee during cancellation */ export declare const CANCEL_RATE = 1.5; /** * Multiplier used to determine a transaction's increased gas fee during speed up */ export declare const SPEED_UP_RATE = 1.1; /** * The name of the {@link TransactionController}. */ declare const controllerName = "TransactionController"; /** * The external actions available to the {@link TransactionController}. */ declare type AllowedActions = AddApprovalRequest; /** * The messenger of the {@link TransactionController}. */ export declare type TransactionControllerMessenger = RestrictedControllerMessenger; /** * Controller responsible for submitting and managing transactions. */ export declare class TransactionController extends BaseController { private ethQuery; private readonly nonceTracker; private registry; private readonly provider; private handle?; private readonly mutex; private readonly getNetworkState; private readonly messagingSystem; private readonly incomingTransactionHelper; private failTransaction; private registryLookup; /** * EventEmitter instance used to listen to specific transactional events */ hub: EventEmitter; /** * Name of this controller used during composition */ name: string; /** * Method used to sign transactions */ sign?: (transaction: TypedTransaction, from: string) => Promise; /** * Creates a TransactionController instance. * * @param options - The controller options. * @param options.blockTracker - The block tracker used to poll for new blocks data. * @param options.getNetworkState - Gets the state of the network controller. * @param options.getSelectedAddress - Gets the address of the currently selected account. * @param options.incomingTransactions - Configuration options for incoming transaction support. * @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data. * @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers. * @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled. * @param options.incomingTransactions.updateTransactions - Whether or not to update local transactions using remote transaction data. * @param options.messenger - The controller messenger. * @param options.onNetworkStateChange - Allows subscribing to network controller state changes. * @param options.provider - The provider used to create the underlying EthQuery instance. * @param config - Initial options used to configure this controller. * @param state - Initial state to set on this controller. */ constructor({ blockTracker, getNetworkState, getSelectedAddress, incomingTransactions, messenger, onNetworkStateChange, provider, }: { blockTracker: BlockTracker; getNetworkState: () => NetworkState; getSelectedAddress: () => string; incomingTransactions: { apiKey?: string; includeTokenTransfers?: boolean; isEnabled?: () => boolean; updateTransactions?: boolean; }; messenger: TransactionControllerMessenger; onNetworkStateChange: (listener: (state: NetworkState) => void) => void; provider: Provider; }, config?: Partial, state?: Partial); /** * Starts a new polling interval. * * @param interval - The polling interval used to fetch new transaction statuses. */ poll(interval?: number): Promise; /** * Handle new method data request. * * @param fourBytePrefix - The method prefix. * @returns The method data object corresponding to the given signature prefix. */ handleMethodData(fourBytePrefix: string): Promise; /** * Add a new unapproved transaction to state. Parameters will be validated, a * unique transaction id will be generated, and gas and gasPrice will be calculated * if not provided. If A `:unapproved` hub event will be emitted once added. * * @param transaction - The transaction object to add. * @param opts - Additional options to control how the transaction is added. * @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction. * @param opts.origin - The origin of the transaction request, such as a dApp hostname. * @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled. * @returns Object containing a promise resolving to the transaction hash if approved. */ addTransaction(transaction: Transaction, { deviceConfirmedOn, origin, requireApproval, }?: { deviceConfirmedOn?: WalletDevice; origin?: string; requireApproval?: boolean | undefined; }): Promise; startIncomingTransactionPolling(): void; stopIncomingTransactionPolling(): void; updateIncomingTransactions(): Promise; /** * Creates approvals for all unapproved transactions persisted. */ initApprovals(): void; /** * Attempts to cancel a transaction based on its ID by setting its status to "rejected" * and emitting a `:finished` hub event. * * @param transactionID - The ID of the transaction to cancel. * @param gasValues - The gas values to use for the cancellation transaction. */ stopTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values): Promise; /** * Attempts to speed up a transaction increasing transaction gasPrice by ten percent. * * @param transactionID - The ID of the transaction to speed up. * @param gasValues - The gas values to use for the speed up transation. */ speedUpTransaction(transactionID: string, gasValues?: GasPriceValue | FeeMarketEIP1559Values): Promise; /** * Estimates required gas for a given transaction. * * @param transaction - The transaction to estimate gas for. * @returns The gas and gas price. */ estimateGas(transaction: Transaction): Promise<{ gas: string; gasPrice: any; estimateGasError?: undefined; } | { gas: string; gasPrice: any; estimateGasError: string | undefined; }>; /** * Check the status of submitted transactions on the network to determine whether they have * been included in a block. Any that have been included in a block are marked as confirmed. */ queryTransactionStatuses(): Promise; /** * Updates an existing transaction in state. * * @param transactionMeta - The new transaction to store in state. */ updateTransaction(transactionMeta: TransactionMeta): void; /** * Removes all transactions from state, optionally based on the current network. * * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the * current network. If `true`, all transactions are wiped. * @param address - If specified, only transactions originating from this address will be * wiped on current network. */ wipeTransactions(ignoreNetwork?: boolean, address?: string): void; startIncomingTransactionProcessing(): void; stopIncomingTransactionProcessing(): void; private processApproval; /** * Approves a transaction and updates it's status in state. If this is not a * retry transaction, a nonce will be generated. The transaction is signed * using the sign configuration property, then published to the blockchain. * A `:finished` hub event is fired after success or failure. * * @param transactionID - The ID of the transaction to approve. */ private approveTransaction; /** * Cancels a transaction based on its ID by setting its status to "rejected" * and emitting a `:finished` hub event. * * @param transactionID - The ID of the transaction to cancel. */ private cancelTransaction; /** * Trim the amount of transactions that are set on the state. Checks * if the length of the tx history is longer then desired persistence * limit and then if it is removes the oldest confirmed or rejected tx. * Pending or unapproved transactions will not be removed by this * operation. For safety of presenting a fully functional transaction UI * representation, this function will not break apart transactions with the * same nonce, created on the same day, per network. Not accounting for transactions of the same * nonce, same day and network combo can result in confusing or broken experiences * in the UI. The transactions are then updated using the BaseController update. * * @param transactions - The transactions to be applied to the state. * @returns The trimmed list of transactions. */ private trimTransactionsForState; /** * Determines if the transaction is in a final state. * * @param status - The transaction status. * @returns Whether the transaction is in a final state. */ private isFinalState; /** * Whether the transaction has at least completed all local processing. * * @param status - The transaction status. * @returns Whether the transaction is in a final state. */ private isLocalFinalState; /** * Method to verify the state of a transaction using the Blockchain as a source of truth. * * @param meta - The local transaction to verify on the blockchain. * @returns A tuple containing the updated transaction, and whether or not an update was required. */ private blockchainTransactionStateReconciler; /** * Method to check if a tx has failed according to their receipt * According to the Web3 docs: * TRUE if the transaction was successful, FALSE if the EVM reverted the transaction. * The receipt is not available for pending transactions and returns null. * * @param txHash - The transaction hash. * @returns Whether the transaction has failed. */ private checkTxReceiptStatusIsFailed; private requestApproval; private getTransaction; private getApprovalId; private isTransactionCompleted; private getChainAndNetworkId; private prepareUnsignedEthTx; /** * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for * specifying which chain, network, hardfork and EIPs to support for * a transaction. By referencing this configuration, and analyzing the fields * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718 * transaction type to use. * * @returns common configuration object */ private getCommonConfiguration; private onIncomingTransactions; private onUpdatedLastFetchedBlockNumbers; } export default TransactionController; //# sourceMappingURL=TransactionController.d.ts.map