@metamask/transaction-controller 11.0.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -4
- package/dist/EtherscanRemoteTransactionSource.d.ts +1 -1
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +1 -1
- package/dist/EtherscanRemoteTransactionSource.js +11 -11
- package/dist/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/IncomingTransactionHelper.js +2 -7
- package/dist/IncomingTransactionHelper.js.map +1 -1
- package/dist/TransactionController.d.ts +13 -3
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +48 -39
- package/dist/TransactionController.js.map +1 -1
- package/dist/constants.d.ts +3 -19
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -20
- package/dist/constants.js.map +1 -1
- package/dist/external-transactions.js +5 -5
- package/dist/external-transactions.js.map +1 -1
- package/dist/transaction-type.d.ts +14 -0
- package/dist/transaction-type.d.ts.map +1 -0
- package/dist/transaction-type.js +114 -0
- package/dist/transaction-type.js.map +1 -0
- package/dist/types.d.ts +128 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +99 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +5 -15
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -29
- package/dist/utils.js.map +1 -1
- package/package.json +13 -11
package/dist/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WalletDevice = exports.TransactionStatus = void 0;
|
|
3
|
+
exports.TransactionType = exports.WalletDevice = exports.TransactionStatus = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The status of the transaction. Each status represents the state of the transaction internally
|
|
6
6
|
* in the wallet. Some of these correspond with the state of the transaction on the network, but
|
|
@@ -27,4 +27,102 @@ var WalletDevice;
|
|
|
27
27
|
WalletDevice["MM_EXTENSION"] = "metamask_extension";
|
|
28
28
|
WalletDevice["OTHER"] = "other_device";
|
|
29
29
|
})(WalletDevice = exports.WalletDevice || (exports.WalletDevice = {}));
|
|
30
|
+
/**
|
|
31
|
+
* The type of the transaction.
|
|
32
|
+
*/
|
|
33
|
+
var TransactionType;
|
|
34
|
+
(function (TransactionType) {
|
|
35
|
+
/**
|
|
36
|
+
* A transaction sending a network's native asset to a recipient.
|
|
37
|
+
*/
|
|
38
|
+
TransactionType["cancel"] = "cancel";
|
|
39
|
+
/**
|
|
40
|
+
* A transaction that is interacting with a smart contract's methods that we
|
|
41
|
+
* have not treated as a special case, such as approve, transfer, and
|
|
42
|
+
* transferfrom.
|
|
43
|
+
*/
|
|
44
|
+
TransactionType["contractInteraction"] = "contractInteraction";
|
|
45
|
+
/**
|
|
46
|
+
* A transaction that deployed a smart contract.
|
|
47
|
+
*/
|
|
48
|
+
TransactionType["deployContract"] = "contractDeployment";
|
|
49
|
+
/**
|
|
50
|
+
* A transaction for Ethereum decryption.
|
|
51
|
+
*/
|
|
52
|
+
TransactionType["ethDecrypt"] = "eth_decrypt";
|
|
53
|
+
/**
|
|
54
|
+
* A transaction for getting an encryption public key.
|
|
55
|
+
*/
|
|
56
|
+
TransactionType["ethGetEncryptionPublicKey"] = "eth_getEncryptionPublicKey";
|
|
57
|
+
/**
|
|
58
|
+
* An incoming (deposit) transaction.
|
|
59
|
+
*/
|
|
60
|
+
TransactionType["incoming"] = "incoming";
|
|
61
|
+
/**
|
|
62
|
+
* A transaction for personal sign.
|
|
63
|
+
*/
|
|
64
|
+
TransactionType["personalSign"] = "personal_sign";
|
|
65
|
+
/**
|
|
66
|
+
* When a transaction is failed it can be retried by
|
|
67
|
+
* resubmitting the same transaction with a higher gas fee. This type is also used
|
|
68
|
+
* to speed up pending transactions. This is accomplished by creating a new tx with
|
|
69
|
+
* the same nonce and higher gas fees.
|
|
70
|
+
*/
|
|
71
|
+
TransactionType["retry"] = "retry";
|
|
72
|
+
/**
|
|
73
|
+
* A transaction sending a network's native asset to a recipient.
|
|
74
|
+
*/
|
|
75
|
+
TransactionType["simpleSend"] = "simpleSend";
|
|
76
|
+
/**
|
|
77
|
+
* A transaction that is signing a message.
|
|
78
|
+
*/
|
|
79
|
+
TransactionType["sign"] = "eth_sign";
|
|
80
|
+
/**
|
|
81
|
+
* A transaction that is signing typed data.
|
|
82
|
+
*/
|
|
83
|
+
TransactionType["signTypedData"] = "eth_signTypedData";
|
|
84
|
+
/**
|
|
85
|
+
* A transaction sending a network's native asset to a recipient.
|
|
86
|
+
*/
|
|
87
|
+
TransactionType["smart"] = "smart";
|
|
88
|
+
/**
|
|
89
|
+
* A transaction swapping one token for another through MetaMask Swaps.
|
|
90
|
+
*/
|
|
91
|
+
TransactionType["swap"] = "swap";
|
|
92
|
+
/**
|
|
93
|
+
* Similar to the approve type, a swap approval is a special case of ERC20
|
|
94
|
+
* approve method that requests an allowance of the token to spend on behalf
|
|
95
|
+
* of the user for the MetaMask Swaps contract. The first swap for any token
|
|
96
|
+
* will have an accompanying swapApproval transaction.
|
|
97
|
+
*/
|
|
98
|
+
TransactionType["swapApproval"] = "swapApproval";
|
|
99
|
+
/**
|
|
100
|
+
* A token transaction requesting an allowance of the token to spend on
|
|
101
|
+
* behalf of the user.
|
|
102
|
+
*/
|
|
103
|
+
TransactionType["tokenMethodApprove"] = "approve";
|
|
104
|
+
/**
|
|
105
|
+
* A token transaction transferring tokens from an account that the sender
|
|
106
|
+
* has an allowance of. The method is prefixed with safe because when calling
|
|
107
|
+
* this method the contract checks to ensure that the receiver is an address
|
|
108
|
+
* capable of handling the token being sent.
|
|
109
|
+
*/
|
|
110
|
+
TransactionType["tokenMethodSafeTransferFrom"] = "safetransferfrom";
|
|
111
|
+
/**
|
|
112
|
+
* A token transaction where the user is sending tokens that they own to
|
|
113
|
+
* another address.
|
|
114
|
+
*/
|
|
115
|
+
TransactionType["tokenMethodTransfer"] = "transfer";
|
|
116
|
+
/**
|
|
117
|
+
* A token transaction transferring tokens from an account that the sender
|
|
118
|
+
* has an allowance of. For more information on allowances, see the approve
|
|
119
|
+
* type.
|
|
120
|
+
*/
|
|
121
|
+
TransactionType["tokenMethodTransferFrom"] = "transferfrom";
|
|
122
|
+
/**
|
|
123
|
+
* A token transaction requesting an allowance of all of a user's tokens to
|
|
124
|
+
* spend on behalf of the user.
|
|
125
|
+
*/
|
|
126
|
+
TransactionType["tokenMethodSetApprovalForAll"] = "setapprovalforall";
|
|
127
|
+
})(TransactionType = exports.TransactionType || (exports.TransactionType = {}));
|
|
30
128
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAiNA;;;;GAIG;AACH,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B,0CAAqB,CAAA;IACrB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,wCAAmB,CAAA;IACnB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;AAC3B,CAAC,EAVW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAU5B;AAED;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mDAAmC,CAAA;IACnC,sCAAsB,CAAA;AACxB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB","sourcesContent":["import type { Hex } from '@metamask/utils';\nimport type { Operation } from 'fast-json-patch';\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta =\n | ({\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n } & TransactionMetaBase)\n | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase);\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * Unique ID to prevent duplicate requests.\n */\n actionId?: string;\n\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * The timestamp for when the block was collated.\n */\n blockTimestamp?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId?: Hex;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * The default estimate for gas.\n */\n defaultGasEstimates?: string;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * The estimated base fee of the transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * A hex string of the transaction hash, used to identify the transaction on the network.\n */\n hash?: string;\n\n /**\n * A history of mutations to TransactionMeta.\n */\n history?: TransactionHistory;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * The original gas estimation of the transaction.\n */\n originalGasEstimate?: string;\n\n /**\n * The transaction's 'r' value as a hex string.\n */\n r?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTx?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction hash.\n */\n replacedBy?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction ID.\n */\n replacedById?: string;\n\n /**\n * The transaction's 's' value as a hex string.\n */\n s?: string;\n\n /**\n * Response from security validator.\n */\n securityAlertResponse?: Record<string, unknown>;\n\n /**\n * An array of entries that describe the user's journey through the send flow.\n * This is purely attached to state logs for troubleshooting and support.\n */\n sendFlowHistory?: SendFlowHistoryEntry[];\n\n /**\n * The time the transaction was submitted to the network, in Unix epoch time (ms).\n */\n submittedTime?: number;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Underlying Transaction object.\n */\n txParams: TransactionParams;\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * The transaction's 'v' value as a hex string.\n */\n v?: string;\n\n /**\n * The gas limit supplied by user.\n */\n userEditedGasLimit?: boolean;\n\n /**\n * Estimate level user selected.\n */\n userFeeLevel?: string;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n};\n\nexport type SendFlowHistoryEntry = {\n /**\n * String to indicate user interaction information.\n */\n entry: string;\n\n /**\n * Timestamp associated with this entry.\n */\n timestamp: number;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n dropped = 'dropped',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport interface TransactionParams {\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * same as gasLimit?\n */\n gas?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Price per gas for legacy txs\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority\n * fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n}\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport interface TransactionReceipt {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: number;\n}\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport interface Log {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n}\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * The networkId of the current network.\n */\n currentNetworkId: string;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\nexport interface RemoteTransactionSource {\n /**\n * @param chainId - The chainId of the current network.\n * @param networkId - The networkId of the current network.\n * @returns Whether the remote transaction source supports the specified network.\n */\n isSupportedNetwork: (chainId: Hex, networkId: string) => boolean;\n\n /**\n * @returns An array of additional keys to use when caching the last fetched block number.\n */\n getLastBlockVariations?: () => string[];\n\n /**\n * @param request - A request object containing data such as the address and chain ID.\n * @returns An array of transaction metadata for the retrieved transactions.\n */\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport interface DappSuggestedGasFees {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n}\n\n/**\n * A transaction history operation that includes a note and timestamp.\n */\ntype ExtendedHistoryOperation = Operation & {\n note?: string;\n timestamp?: number;\n};\n\n/**\n * A transaction history entry that includes the ExtendedHistoryOperation as the first element.\n */\nexport type TransactionHistoryEntry = [\n ExtendedHistoryOperation,\n ...Operation[],\n];\n\n/**\n * A transaction history that includes the transaction meta as the first element.\n * And the rest of the elements are the operation arrays that were applied to the transaction meta.\n */\nexport type TransactionHistory = [\n TransactionMeta,\n ...TransactionHistoryEntry[],\n];\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAwNA;;;;GAIG;AACH,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B,0CAAqB,CAAA;IACrB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,wCAAmB,CAAA;IACnB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;AAC3B,CAAC,EAVW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAU5B;AAED;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mDAAmC,CAAA;IACnC,sCAAsB,CAAA;AACxB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAED;;GAEG;AACH,IAAY,eA+GX;AA/GD,WAAY,eAAe;IACzB;;OAEG;IACH,oCAAiB,CAAA;IAEjB;;;;OAIG;IACH,8DAA2C,CAAA;IAE3C;;OAEG;IACH,wDAAqC,CAAA;IAErC;;OAEG;IACH,6CAA0B,CAAA;IAE1B;;OAEG;IACH,2EAAwD,CAAA;IAExD;;OAEG;IACH,wCAAqB,CAAA;IAErB;;OAEG;IACH,iDAA8B,CAAA;IAE9B;;;;;OAKG;IACH,kCAAe,CAAA;IAEf;;OAEG;IACH,4CAAyB,CAAA;IAEzB;;OAEG;IACH,oCAAiB,CAAA;IAEjB;;OAEG;IACH,sDAAmC,CAAA;IAEnC;;OAEG;IACH,kCAAe,CAAA;IAEf;;OAEG;IACH,gCAAa,CAAA;IAEb;;;;;OAKG;IACH,gDAA6B,CAAA;IAE7B;;;OAGG;IACH,iDAA8B,CAAA;IAE9B;;;;;OAKG;IACH,mEAAgD,CAAA;IAEhD;;;OAGG;IACH,mDAAgC,CAAA;IAEhC;;;;OAIG;IACH,2DAAwC,CAAA;IAExC;;;OAGG;IACH,qEAAkD,CAAA;AACpD,CAAC,EA/GW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QA+G1B","sourcesContent":["import type { Hex } from '@metamask/utils';\nimport type { Operation } from 'fast-json-patch';\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta =\n | ({\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n } & TransactionMetaBase)\n | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase);\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * Unique ID to prevent duplicate requests.\n */\n actionId?: string;\n\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * The timestamp for when the block was collated.\n */\n blockTimestamp?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId: Hex;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * The default estimate for gas.\n */\n defaultGasEstimates?: string;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * The estimated base fee of the transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Which estimate level that the API suggested.\n */\n estimateSuggested?: string;\n\n /**\n * Which estimate level was used\n */\n estimateUsed?: string;\n\n /**\n * A hex string of the transaction hash, used to identify the transaction on the network.\n */\n hash?: string;\n\n /**\n * A history of mutations to TransactionMeta.\n */\n history?: TransactionHistory;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Network code as per EIP-155 for this transaction\n *\n * @deprecated Use `chainId` instead.\n */\n readonly networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * The original gas estimation of the transaction.\n */\n originalGasEstimate?: string;\n\n /**\n * The transaction's 'r' value as a hex string.\n */\n r?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTx?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction hash.\n */\n replacedBy?: string;\n\n /**\n * When the transaction is dropped, this is the replacement transaction ID.\n */\n replacedById?: string;\n\n /**\n * The transaction's 's' value as a hex string.\n */\n s?: string;\n\n /**\n * Response from security validator.\n */\n securityAlertResponse?: Record<string, unknown>;\n\n /**\n * An array of entries that describe the user's journey through the send flow.\n * This is purely attached to state logs for troubleshooting and support.\n */\n sendFlowHistory?: SendFlowHistoryEntry[];\n\n /**\n * The time the transaction was submitted to the network, in Unix epoch time (ms).\n */\n submittedTime?: number;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Underlying Transaction object.\n */\n txParams: TransactionParams;\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * The type of transaction such as `cancel` or `swap`.\n */\n type?: TransactionType;\n\n /**\n * The gas limit supplied by user.\n */\n userEditedGasLimit?: boolean;\n\n /**\n * Estimate level user selected.\n */\n userFeeLevel?: string;\n\n /**\n * The transaction's 'v' value as a hex string.\n */\n v?: string;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n};\n\nexport type SendFlowHistoryEntry = {\n /**\n * String to indicate user interaction information.\n */\n entry: string;\n\n /**\n * Timestamp associated with this entry.\n */\n timestamp: number;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n dropped = 'dropped',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * The type of the transaction.\n */\nexport enum TransactionType {\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n cancel = 'cancel',\n\n /**\n * A transaction that is interacting with a smart contract's methods that we\n * have not treated as a special case, such as approve, transfer, and\n * transferfrom.\n */\n contractInteraction = 'contractInteraction',\n\n /**\n * A transaction that deployed a smart contract.\n */\n deployContract = 'contractDeployment',\n\n /**\n * A transaction for Ethereum decryption.\n */\n ethDecrypt = 'eth_decrypt',\n\n /**\n * A transaction for getting an encryption public key.\n */\n ethGetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n\n /**\n * An incoming (deposit) transaction.\n */\n incoming = 'incoming',\n\n /**\n * A transaction for personal sign.\n */\n personalSign = 'personal_sign',\n\n /**\n * When a transaction is failed it can be retried by\n * resubmitting the same transaction with a higher gas fee. This type is also used\n * to speed up pending transactions. This is accomplished by creating a new tx with\n * the same nonce and higher gas fees.\n */\n retry = 'retry',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n simpleSend = 'simpleSend',\n\n /**\n * A transaction that is signing a message.\n */\n sign = 'eth_sign',\n\n /**\n * A transaction that is signing typed data.\n */\n signTypedData = 'eth_signTypedData',\n\n /**\n * A transaction sending a network's native asset to a recipient.\n */\n smart = 'smart',\n\n /**\n * A transaction swapping one token for another through MetaMask Swaps.\n */\n swap = 'swap',\n\n /**\n * Similar to the approve type, a swap approval is a special case of ERC20\n * approve method that requests an allowance of the token to spend on behalf\n * of the user for the MetaMask Swaps contract. The first swap for any token\n * will have an accompanying swapApproval transaction.\n */\n swapApproval = 'swapApproval',\n\n /**\n * A token transaction requesting an allowance of the token to spend on\n * behalf of the user.\n */\n tokenMethodApprove = 'approve',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. The method is prefixed with safe because when calling\n * this method the contract checks to ensure that the receiver is an address\n * capable of handling the token being sent.\n */\n tokenMethodSafeTransferFrom = 'safetransferfrom',\n\n /**\n * A token transaction where the user is sending tokens that they own to\n * another address.\n */\n tokenMethodTransfer = 'transfer',\n\n /**\n * A token transaction transferring tokens from an account that the sender\n * has an allowance of. For more information on allowances, see the approve\n * type.\n */\n tokenMethodTransferFrom = 'transferfrom',\n\n /**\n * A token transaction requesting an allowance of all of a user's tokens to\n * spend on behalf of the user.\n */\n tokenMethodSetApprovalForAll = 'setapprovalforall',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport interface TransactionParams {\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * same as gasLimit?\n */\n gas?: string;\n\n /**\n * Maxmimum number of units of gas to use for this transaction.\n */\n gasLimit?: string;\n\n /**\n * Price per gas for legacy txs\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum amount per gas to pay for the transaction, including the priority\n * fee.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum amount per gas to give to validator as incentive.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n\n /**\n * Type of transaction.\n * 0x0 indicates a legacy transaction.\n */\n type?: string;\n}\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport interface TransactionReceipt {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: number;\n}\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport interface Log {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n}\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\nexport interface RemoteTransactionSource {\n /**\n * @param chainId - The chainId of the current network.\n * @returns Whether the remote transaction source supports the specified network.\n */\n isSupportedNetwork: (chainId: Hex) => boolean;\n\n /**\n * @returns An array of additional keys to use when caching the last fetched block number.\n */\n getLastBlockVariations?: () => string[];\n\n /**\n * @param request - A request object containing data such as the address and chain ID.\n * @returns An array of transaction metadata for the retrieved transactions.\n */\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport interface DappSuggestedGasFees {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n}\n\n/**\n * A transaction history operation that includes a note and timestamp.\n */\ntype ExtendedHistoryOperation = Operation & {\n note?: string;\n timestamp?: number;\n};\n\n/**\n * A transaction history entry that includes the ExtendedHistoryOperation as the first element.\n */\nexport type TransactionHistoryEntry = [\n ExtendedHistoryOperation,\n ...Operation[],\n];\n\n/**\n * A transaction history that includes the transaction meta as the first element.\n * And the rest of the elements are the operation arrays that were applied to the transaction meta.\n */\nexport type TransactionHistory = [\n TransactionMeta,\n ...TransactionHistoryEntry[],\n];\n\n/**\n * Result of inferring the transaction type.\n */\nexport type InferTransactionTypeResult = {\n /**\n * The contract code, in hex format if it exists. '0x0' or\n * '0x' are also indicators of non-existent contract code.\n */\n getCodeResponse?: string | null;\n\n /**\n * The type of transaction\n */\n type: TransactionType;\n};\n"]}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Hex } from '@metamask/utils';
|
|
2
1
|
import type { Transaction as NonceTrackerTransaction } from 'nonce-tracker/dist/NonceTracker';
|
|
3
2
|
import type { GasPriceValue, FeeMarketEIP1559Values } from './TransactionController';
|
|
4
3
|
import { TransactionStatus } from './types';
|
|
@@ -16,8 +15,9 @@ export declare function normalizeTxParams(txParams: TransactionParams): Transact
|
|
|
16
15
|
* the event of any validation error.
|
|
17
16
|
*
|
|
18
17
|
* @param txParams - Transaction params object to validate.
|
|
18
|
+
* @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.
|
|
19
19
|
*/
|
|
20
|
-
export declare function validateTxParams(txParams: TransactionParams): void;
|
|
20
|
+
export declare function validateTxParams(txParams: TransactionParams, isEIP1559Compatible?: boolean): void;
|
|
21
21
|
/**
|
|
22
22
|
* Checks if a transaction is EIP-1559 by checking for the existence of
|
|
23
23
|
* maxFeePerGas and maxPriorityFeePerGas within its parameters.
|
|
@@ -25,10 +25,10 @@ export declare function validateTxParams(txParams: TransactionParams): void;
|
|
|
25
25
|
* @param txParams - Transaction params object to add.
|
|
26
26
|
* @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
|
|
27
27
|
*/
|
|
28
|
-
export declare
|
|
28
|
+
export declare function isEIP1559Transaction(txParams: TransactionParams): boolean;
|
|
29
29
|
export declare const validateGasValues: (gasValues: GasPriceValue | FeeMarketEIP1559Values) => void;
|
|
30
|
-
export declare const isFeeMarketEIP1559Values: (gasValues?: GasPriceValue | FeeMarketEIP1559Values
|
|
31
|
-
export declare const isGasPriceValue: (gasValues?: GasPriceValue | FeeMarketEIP1559Values
|
|
30
|
+
export declare const isFeeMarketEIP1559Values: (gasValues?: GasPriceValue | FeeMarketEIP1559Values) => gasValues is FeeMarketEIP1559Values;
|
|
31
|
+
export declare const isGasPriceValue: (gasValues?: GasPriceValue | FeeMarketEIP1559Values) => gasValues is GasPriceValue;
|
|
32
32
|
export declare const getIncreasedPriceHex: (value: number, rate: number) => string;
|
|
33
33
|
export declare const getIncreasedPriceFromExisting: (value: string | undefined, rate: number) => string;
|
|
34
34
|
/**
|
|
@@ -49,16 +49,6 @@ export declare function validateMinimumIncrease(proposed: string, min: string):
|
|
|
49
49
|
* @returns Array of transactions formatted for the nonce tracker.
|
|
50
50
|
*/
|
|
51
51
|
export declare function getAndFormatTransactionsForNonceTracker(fromAddress: string, transactionStatus: TransactionStatus, transactions: TransactionMeta[]): NonceTrackerTransaction[];
|
|
52
|
-
/**
|
|
53
|
-
* Checks whether a given transaction matches the specified network or chain ID.
|
|
54
|
-
* This function is used to determine if a transaction is relevant to the current network or chain.
|
|
55
|
-
*
|
|
56
|
-
* @param transaction - The transaction metadata to check.
|
|
57
|
-
* @param chainId - The chain ID of the current network.
|
|
58
|
-
* @param networkId - The network ID of the current network.
|
|
59
|
-
* @returns A boolean value indicating whether the transaction matches the current network or chain ID.
|
|
60
|
-
*/
|
|
61
|
-
export declare function transactionMatchesNetwork(transaction: TransactionMeta, chainId: Hex, networkId: string | null): boolean;
|
|
62
52
|
/**
|
|
63
53
|
* Validates that a transaction is unapproved.
|
|
64
54
|
* Throws if the transaction is not unapproved.
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,IAAI,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAElE,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAmBrE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,qBAS5D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,mBAAmB,UAAO,QAyD3B;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAOzE;AAED,eAAO,MAAM,iBAAiB,cACjB,aAAa,GAAG,sBAAsB,SAUlD,CAAC;AAEF,eAAO,MAAM,wBAAwB,eACvB,aAAa,GAAG,sBAAsB,wCAGuB,CAAC;AAE5E,eAAO,MAAM,eAAe,eACd,aAAa,GAAG,sBAAsB,+BAEE,CAAC;AAEvD,eAAO,MAAM,oBAAoB,UAAW,MAAM,QAAQ,MAAM,KAAG,MACF,CAAC;AAElE,eAAO,MAAM,6BAA6B,UACjC,MAAM,GAAG,SAAS,QACnB,MAAM,KACX,MAEF,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAQpE;AAED;;;;;;;GAOG;AACH,wBAAgB,uCAAuC,CACrD,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE,eAAe,EAAE,GAC9B,uBAAuB,EAAE,CAsB3B;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,eAAe,EAAE,eAAe,GAAG,SAAS,EAC5C,MAAM,EAAE,MAAM,QAQf"}
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateIfTransactionUnapproved = exports.
|
|
3
|
+
exports.validateIfTransactionUnapproved = exports.getAndFormatTransactionsForNonceTracker = exports.validateMinimumIncrease = exports.getIncreasedPriceFromExisting = exports.getIncreasedPriceHex = exports.isGasPriceValue = exports.isFeeMarketEIP1559Values = exports.validateGasValues = exports.isEIP1559Transaction = exports.validateTxParams = exports.normalizeTxParams = exports.ESTIMATE_GAS_ERROR = void 0;
|
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
6
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
6
7
|
const types_1 = require("./types");
|
|
7
8
|
exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
@@ -17,6 +18,7 @@ const NORMALIZERS = {
|
|
|
17
18
|
maxFeePerGas: (maxFeePerGas) => (0, ethereumjs_util_1.addHexPrefix)(maxFeePerGas),
|
|
18
19
|
maxPriorityFeePerGas: (maxPriorityFeePerGas) => (0, ethereumjs_util_1.addHexPrefix)(maxPriorityFeePerGas),
|
|
19
20
|
estimatedBaseFee: (maxPriorityFeePerGas) => (0, ethereumjs_util_1.addHexPrefix)(maxPriorityFeePerGas),
|
|
21
|
+
type: (type) => (type === '0x0' ? '0x0' : undefined),
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Normalizes properties on transaction params.
|
|
@@ -40,31 +42,35 @@ exports.normalizeTxParams = normalizeTxParams;
|
|
|
40
42
|
* the event of any validation error.
|
|
41
43
|
*
|
|
42
44
|
* @param txParams - Transaction params object to validate.
|
|
45
|
+
* @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.
|
|
43
46
|
*/
|
|
44
|
-
function validateTxParams(txParams) {
|
|
47
|
+
function validateTxParams(txParams, isEIP1559Compatible = true) {
|
|
45
48
|
if (!txParams.from ||
|
|
46
49
|
typeof txParams.from !== 'string' ||
|
|
47
50
|
!(0, controller_utils_1.isValidHexAddress)(txParams.from)) {
|
|
48
|
-
throw
|
|
51
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "from" address: ${txParams.from} must be a valid string.`);
|
|
52
|
+
}
|
|
53
|
+
if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {
|
|
54
|
+
throw rpc_errors_1.rpcErrors.invalidParams('Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559');
|
|
49
55
|
}
|
|
50
56
|
if (txParams.to === '0x' || txParams.to === undefined) {
|
|
51
57
|
if (txParams.data) {
|
|
52
58
|
delete txParams.to;
|
|
53
59
|
}
|
|
54
60
|
else {
|
|
55
|
-
throw
|
|
61
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "to" address: ${txParams.to} must be a valid string.`);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
else if (txParams.to !== undefined && !(0, controller_utils_1.isValidHexAddress)(txParams.to)) {
|
|
59
|
-
throw
|
|
65
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "to" address: ${txParams.to} must be a valid string.`);
|
|
60
66
|
}
|
|
61
67
|
if (txParams.value !== undefined) {
|
|
62
68
|
const value = txParams.value.toString();
|
|
63
69
|
if (value.includes('-')) {
|
|
64
|
-
throw
|
|
70
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "value": ${value} is not a positive number.`);
|
|
65
71
|
}
|
|
66
72
|
if (value.includes('.')) {
|
|
67
|
-
throw
|
|
73
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "value": ${value} number must be denominated in wei.`);
|
|
68
74
|
}
|
|
69
75
|
const intValue = parseInt(txParams.value, 10);
|
|
70
76
|
const isValid = Number.isFinite(intValue) &&
|
|
@@ -72,7 +78,7 @@ function validateTxParams(txParams) {
|
|
|
72
78
|
!isNaN(Number(value)) &&
|
|
73
79
|
Number.isSafeInteger(intValue);
|
|
74
80
|
if (!isValid) {
|
|
75
|
-
throw
|
|
81
|
+
throw rpc_errors_1.rpcErrors.invalidParams(`Invalid "value": ${value} number must be a valid number.`);
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
}
|
|
@@ -84,11 +90,11 @@ exports.validateTxParams = validateTxParams;
|
|
|
84
90
|
* @param txParams - Transaction params object to add.
|
|
85
91
|
* @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
|
|
86
92
|
*/
|
|
87
|
-
|
|
93
|
+
function isEIP1559Transaction(txParams) {
|
|
88
94
|
const hasOwnProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
89
95
|
return (hasOwnProp(txParams, 'maxFeePerGas') &&
|
|
90
96
|
hasOwnProp(txParams, 'maxPriorityFeePerGas'));
|
|
91
|
-
}
|
|
97
|
+
}
|
|
92
98
|
exports.isEIP1559Transaction = isEIP1559Transaction;
|
|
93
99
|
const validateGasValues = (gasValues) => {
|
|
94
100
|
Object.keys(gasValues).forEach((key) => {
|
|
@@ -157,25 +163,6 @@ function getAndFormatTransactionsForNonceTracker(fromAddress, transactionStatus,
|
|
|
157
163
|
});
|
|
158
164
|
}
|
|
159
165
|
exports.getAndFormatTransactionsForNonceTracker = getAndFormatTransactionsForNonceTracker;
|
|
160
|
-
/**
|
|
161
|
-
* Checks whether a given transaction matches the specified network or chain ID.
|
|
162
|
-
* This function is used to determine if a transaction is relevant to the current network or chain.
|
|
163
|
-
*
|
|
164
|
-
* @param transaction - The transaction metadata to check.
|
|
165
|
-
* @param chainId - The chain ID of the current network.
|
|
166
|
-
* @param networkId - The network ID of the current network.
|
|
167
|
-
* @returns A boolean value indicating whether the transaction matches the current network or chain ID.
|
|
168
|
-
*/
|
|
169
|
-
function transactionMatchesNetwork(transaction, chainId, networkId) {
|
|
170
|
-
if (transaction.chainId) {
|
|
171
|
-
return transaction.chainId === chainId;
|
|
172
|
-
}
|
|
173
|
-
if (transaction.networkID) {
|
|
174
|
-
return transaction.networkID === networkId;
|
|
175
|
-
}
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
exports.transactionMatchesNetwork = transactionMatchesNetwork;
|
|
179
166
|
/**
|
|
180
167
|
* Validates that a transaction is unapproved.
|
|
181
168
|
* Throws if the trans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S,EAAE;QACzB,OAAO,WAAW,CAAC,SAAS,KAAK,SAAS,CAAC;KAC5C;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,8DAYC;AAED;;;;;;GAMG;AACH,SAAgB,+BAA+B,CAC7C,eAA4C,EAC5C,MAAc;IAEd,IAAI,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,MAAK,yBAAiB,CAAC,UAAU,EAAE;QAC5D,MAAM,IAAI,KAAK,CACb,iBAAiB,MAAM;2BACF,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,EAAE,CAC/C,CAAC;KACH;AACH,CAAC;AAVD,0EAUC","sourcesContent":["import {\n convertHexToDecimal,\n isValidHexAddress,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { addHexPrefix, isHexString } from 'ethereumjs-util';\nimport type { Transaction as NonceTrackerTransaction } from 'nonce-tracker/dist/NonceTracker';\n\nimport type {\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from './TransactionController';\nimport { TransactionStatus } from './types';\nimport type { TransactionParams, TransactionMeta } from './types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => addHexPrefix(data),\n from: (from: string) => addHexPrefix(from).toLowerCase(),\n gas: (gas: string) => addHexPrefix(gas),\n gasLimit: (gas: string) => addHexPrefix(gas),\n gasPrice: (gasPrice: string) => addHexPrefix(gasPrice),\n nonce: (nonce: string) => addHexPrefix(nonce),\n to: (to: string) => addHexPrefix(to).toLowerCase(),\n value: (value: string) => addHexPrefix(value),\n maxFeePerGas: (maxFeePerGas: string) => addHexPrefix(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n addHexPrefix(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n addHexPrefix(maxPriorityFeePerGas),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTxParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n let key: keyof TransactionParams;\n for (key in NORMALIZERS) {\n if (txParams[key as keyof TransactionParams]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]) as never;\n }\n }\n return normalizedTxParams;\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n */\nexport function validateTxParams(txParams: TransactionParams) {\n if (\n !txParams.from ||\n typeof txParams.from !== 'string' ||\n !isValidHexAddress(txParams.from)\n ) {\n throw new Error(\n `Invalid \"from\" address: ${txParams.from} must be a valid string.`,\n );\n }\n\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw new Error(\n `Invalid \"to\" address: ${txParams.to} must be a valid string.`,\n );\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw new Error(\n `Invalid \"to\" address: ${txParams.to} must be a valid string.`,\n );\n }\n\n if (txParams.value !== undefined) {\n const value = txParams.value.toString();\n if (value.includes('-')) {\n throw new Error(`Invalid \"value\": ${value} is not a positive number.`);\n }\n\n if (value.includes('.')) {\n throw new Error(\n `Invalid \"value\": ${value} number must be denominated in wei.`,\n );\n }\n const intValue = parseInt(txParams.value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw new Error(\n `Invalid \"value\": ${value} number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport const isEIP1559Transaction = (txParams: TransactionParams): boolean => {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n};\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isHexString(value)) {\n throw new TypeError(\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\nexport const isFeeMarketEIP1559Values = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is FeeMarketEIP1559Values =>\n (gasValues as FeeMarketEIP1559Values)?.maxFeePerGas !== undefined ||\n (gasValues as FeeMarketEIP1559Values)?.maxPriorityFeePerGas !== undefined;\n\nexport const isGasPriceValue = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is GasPriceValue =>\n (gasValues as GasPriceValue)?.gasPrice !== undefined;\n\nexport const getIncreasedPriceHex = (value: number, rate: number): string =>\n addHexPrefix(`${parseInt(`${value * rate}`, 10).toString(16)}`);\n\nexport const getIncreasedPriceFromExisting = (\n value: string | undefined,\n rate: number,\n): string => {\n return getIncreasedPriceHex(convertHexToDecimal(value), rate);\n};\n\n/**\n * Validates that the proposed value is greater than or equal to the minimum value.\n *\n * @param proposed - The proposed value.\n * @param min - The minimum value.\n * @returns The proposed value.\n * @throws Will throw if the proposed value is too low.\n */\nexport function validateMinimumIncrease(proposed: string, min: string) {\n const proposedDecimal = convertHexToDecimal(proposed);\n const minDecimal = convertHexToDecimal(min);\n if (proposedDecimal >= minDecimal) {\n return proposed;\n }\n const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;\n throw new Error(errorMsg);\n}\n\n/**\n * Helper function to filter and format transactions for the nonce tracker.\n *\n * @param fromAddress - Address of the account from which the transactions to filter from are sent.\n * @param transactionStatus - Status of the transactions for which to filter.\n * @param transactions - Array of transactionMeta objects that have been prefiltered.\n * @returns Array of transactions formatted for the nonce tracker.\n */\nexport function getAndFormatTransactionsForNonceTracker(\n fromAddress: string,\n transactionStatus: TransactionStatus,\n transactions: TransactionMeta[],\n): NonceTrackerTransaction[] {\n return transactions\n .filter(\n ({ status, txParams: { from } }) =>\n status === transactionStatus &&\n from.toLowerCase() === fromAddress.toLowerCase(),\n )\n .map(({ status, txParams: { from, gas, value, nonce } }) => {\n // the only value we care about is the nonce\n // but we need to return the other values to satisfy the type\n // TODO: refactor nonceTracker to not require this\n return {\n status,\n history: [{}],\n txParams: {\n from: from ?? '',\n gas: gas ?? '',\n value: value ?? '',\n nonce: nonce ?? '',\n },\n };\n });\n}\n\n/**\n * Checks whether a given transaction matches the specified network or chain ID.\n * This function is used to determine if a transaction is relevant to the current network or chain.\n *\n * @param transaction - The transaction metadata to check.\n * @param chainId - The chain ID of the current network.\n * @param networkId - The network ID of the current network.\n * @returns A boolean value indicating whether the transaction matches the current network or chain ID.\n */\nexport function transactionMatchesNetwork(\n transaction: TransactionMeta,\n chainId: Hex,\n networkId: string | null,\n) {\n if (transaction.chainId) {\n return transaction.chainId === chainId;\n }\n if (transaction.networkID) {\n return transaction.networkID === networkId;\n }\n return false;\n}\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n `Can only call ${fnName} on an unapproved transaction.\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAGoC;AACpC,qDAAiD;AACjD,qDAA4D;AAO5D,mCAA4C;AAG/B,QAAA,kBAAkB,GAA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Af,eAAe,uBAAf,eAAe,CAAE,MAAM,MAAK,yBAAiB,CAAC,UAAU,EAAE;QAC5D,MAAM,IAAI,KAAK,CACb,iBAAiB,MAAM;2BACF,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,MAAM,EAAE,CAC/C,CAAC;KACH;AACH,CAAC;AAVD,0EAUC","sourcesContent":["import {\n convertHexToDecimal,\n isValidHexAddress,\n} from '@metamask/controller-utils';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { addHexPrefix, isHexString } from 'ethereumjs-util';\nimport type { Transaction as NonceTrackerTransaction } from 'nonce-tracker/dist/NonceTracker';\n\nimport type {\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from './TransactionController';\nimport { TransactionStatus } from './types';\nimport type { TransactionParams, TransactionMeta } from './types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => addHexPrefix(data),\n from: (from: string) => addHexPrefix(from).toLowerCase(),\n gas: (gas: string) => addHexPrefix(gas),\n gasLimit: (gas: string) => addHexPrefix(gas),\n gasPrice: (gasPrice: string) => addHexPrefix(gasPrice),\n nonce: (nonce: string) => addHexPrefix(nonce),\n to: (to: string) => addHexPrefix(to).toLowerCase(),\n value: (value: string) => addHexPrefix(value),\n maxFeePerGas: (maxFeePerGas: string) => addHexPrefix(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n addHexPrefix(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n addHexPrefix(maxPriorityFeePerGas),\n type: (type: string) => (type === '0x0' ? '0x0' : undefined),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTxParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n let key: keyof TransactionParams;\n for (key in NORMALIZERS) {\n if (txParams[key as keyof TransactionParams]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]) as never;\n }\n }\n return normalizedTxParams;\n}\n\n/**\n * Validates the transaction params for required properties and throws in\n * the event of any validation error.\n *\n * @param txParams - Transaction params object to validate.\n * @param isEIP1559Compatible - whether or not the current network supports EIP-1559 transactions.\n */\nexport function validateTxParams(\n txParams: TransactionParams,\n isEIP1559Compatible = true,\n) {\n if (\n !txParams.from ||\n typeof txParams.from !== 'string' ||\n !isValidHexAddress(txParams.from)\n ) {\n throw rpcErrors.invalidParams(\n `Invalid \"from\" address: ${txParams.from} must be a valid string.`,\n );\n }\n\n if (isEIP1559Transaction(txParams) && !isEIP1559Compatible) {\n throw rpcErrors.invalidParams(\n 'Invalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559',\n );\n }\n\n if (txParams.to === '0x' || txParams.to === undefined) {\n if (txParams.data) {\n delete txParams.to;\n } else {\n throw rpcErrors.invalidParams(\n `Invalid \"to\" address: ${txParams.to} must be a valid string.`,\n );\n }\n } else if (txParams.to !== undefined && !isValidHexAddress(txParams.to)) {\n throw rpcErrors.invalidParams(\n `Invalid \"to\" address: ${txParams.to} must be a valid string.`,\n );\n }\n\n if (txParams.value !== undefined) {\n const value = txParams.value.toString();\n if (value.includes('-')) {\n throw rpcErrors.invalidParams(\n `Invalid \"value\": ${value} is not a positive number.`,\n );\n }\n\n if (value.includes('.')) {\n throw rpcErrors.invalidParams(\n `Invalid \"value\": ${value} number must be denominated in wei.`,\n );\n }\n const intValue = parseInt(txParams.value, 10);\n const isValid =\n Number.isFinite(intValue) &&\n !Number.isNaN(intValue) &&\n !isNaN(Number(value)) &&\n Number.isSafeInteger(intValue);\n if (!isValid) {\n throw rpcErrors.invalidParams(\n `Invalid \"value\": ${value} number must be a valid number.`,\n );\n }\n }\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isHexString(value)) {\n throw new TypeError(\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\nexport const isFeeMarketEIP1559Values = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is FeeMarketEIP1559Values =>\n (gasValues as FeeMarketEIP1559Values)?.maxFeePerGas !== undefined ||\n (gasValues as FeeMarketEIP1559Values)?.maxPriorityFeePerGas !== undefined;\n\nexport const isGasPriceValue = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is GasPriceValue =>\n (gasValues as GasPriceValue)?.gasPrice !== undefined;\n\nexport const getIncreasedPriceHex = (value: number, rate: number): string =>\n addHexPrefix(`${parseInt(`${value * rate}`, 10).toString(16)}`);\n\nexport const getIncreasedPriceFromExisting = (\n value: string | undefined,\n rate: number,\n): string => {\n return getIncreasedPriceHex(convertHexToDecimal(value), rate);\n};\n\n/**\n * Validates that the proposed value is greater than or equal to the minimum value.\n *\n * @param proposed - The proposed value.\n * @param min - The minimum value.\n * @returns The proposed value.\n * @throws Will throw if the proposed value is too low.\n */\nexport function validateMinimumIncrease(proposed: string, min: string) {\n const proposedDecimal = convertHexToDecimal(proposed);\n const minDecimal = convertHexToDecimal(min);\n if (proposedDecimal >= minDecimal) {\n return proposed;\n }\n const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;\n throw new Error(errorMsg);\n}\n\n/**\n * Helper function to filter and format transactions for the nonce tracker.\n *\n * @param fromAddress - Address of the account from which the transactions to filter from are sent.\n * @param transactionStatus - Status of the transactions for which to filter.\n * @param transactions - Array of transactionMeta objects that have been prefiltered.\n * @returns Array of transactions formatted for the nonce tracker.\n */\nexport function getAndFormatTransactionsForNonceTracker(\n fromAddress: string,\n transactionStatus: TransactionStatus,\n transactions: TransactionMeta[],\n): NonceTrackerTransaction[] {\n return transactions\n .filter(\n ({ status, txParams: { from } }) =>\n status === transactionStatus &&\n from.toLowerCase() === fromAddress.toLowerCase(),\n )\n .map(({ status, txParams: { from, gas, value, nonce } }) => {\n // the only value we care about is the nonce\n // but we need to return the other values to satisfy the type\n // TODO: refactor nonceTracker to not require this\n return {\n status,\n history: [{}],\n txParams: {\n from: from ?? '',\n gas: gas ?? '',\n value: value ?? '',\n nonce: nonce ?? '',\n },\n };\n });\n}\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n `Can only call ${fnName} on an unapproved transaction.\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/transaction-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -30,15 +30,17 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@ethereumjs/common": "^3.2.0",
|
|
32
32
|
"@ethereumjs/tx": "^4.2.0",
|
|
33
|
-
"@
|
|
34
|
-
"@metamask/
|
|
35
|
-
"@metamask/controller
|
|
33
|
+
"@ethersproject/abi": "^5.7.0",
|
|
34
|
+
"@metamask/approval-controller": "^3.5.2",
|
|
35
|
+
"@metamask/base-controller": "^3.2.2",
|
|
36
|
+
"@metamask/controller-utils": "^5.0.1",
|
|
36
37
|
"@metamask/eth-query": "^3.0.1",
|
|
37
|
-
"@metamask/
|
|
38
|
+
"@metamask/metamask-eth-abis": "^3.0.0",
|
|
39
|
+
"@metamask/network-controller": "^13.0.1",
|
|
40
|
+
"@metamask/rpc-errors": "^6.0.0",
|
|
38
41
|
"@metamask/utils": "^6.2.0",
|
|
39
42
|
"async-mutex": "^0.2.6",
|
|
40
43
|
"eth-method-registry": "1.1.0",
|
|
41
|
-
"eth-rpc-errors": "^4.0.2",
|
|
42
44
|
"ethereumjs-util": "^7.0.10",
|
|
43
45
|
"fast-json-patch": "^3.1.1",
|
|
44
46
|
"lodash": "^4.17.21",
|
|
@@ -55,13 +57,13 @@
|
|
|
55
57
|
"jest": "^27.5.1",
|
|
56
58
|
"sinon": "^9.2.4",
|
|
57
59
|
"ts-jest": "^27.1.4",
|
|
58
|
-
"typedoc": "^0.
|
|
59
|
-
"typedoc-plugin-missing-exports": "^0.
|
|
60
|
-
"typescript": "~4.
|
|
60
|
+
"typedoc": "^0.23.15",
|
|
61
|
+
"typedoc-plugin-missing-exports": "^0.23.0",
|
|
62
|
+
"typescript": "~4.8.4"
|
|
61
63
|
},
|
|
62
64
|
"peerDependencies": {
|
|
63
|
-
"@metamask/approval-controller": "^3.5.
|
|
64
|
-
"@metamask/network-controller": "^
|
|
65
|
+
"@metamask/approval-controller": "^3.5.2",
|
|
66
|
+
"@metamask/network-controller": "^13.0.1",
|
|
65
67
|
"babel-runtime": "^6.26.0"
|
|
66
68
|
},
|
|
67
69
|
"engines": {
|