@metamask/transaction-controller 18.2.0 → 18.3.1
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 +372 -0
- package/dist/TransactionController.d.ts +10 -10
- package/dist/TransactionController.d.ts.map +1 -1
- package/dist/TransactionController.js +50 -38
- package/dist/TransactionController.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.js +4 -0
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.d.ts +1 -2
- package/dist/helpers/PendingTransactionTracker.d.ts.map +1 -1
- package/dist/helpers/PendingTransactionTracker.js +24 -12
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/gas.d.ts.map +1 -1
- package/dist/utils/gas.js +2 -0
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/history.js +8 -2
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/nonce.d.ts.map +1 -1
- package/dist/utils/nonce.js +2 -1
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/swaps.js +4 -0
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/transaction-type.d.ts.map +1 -1
- package/dist/utils/transaction-type.js +19 -12
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +6 -0
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/validation.js +2 -0
- package/dist/utils/validation.js.map +1 -1
- package/package.json +5 -5
- package/dist/EtherscanRemoteTransactionSource.d.ts +0 -15
- package/dist/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/EtherscanRemoteTransactionSource.js +0 -122
- package/dist/EtherscanRemoteTransactionSource.js.map +0 -1
- package/dist/IncomingTransactionHelper.d.ts +0 -25
- package/dist/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/IncomingTransactionHelper.js +0 -198
- package/dist/IncomingTransactionHelper.js.map +0 -1
- package/dist/etherscan.d.ts +0 -64
- package/dist/etherscan.d.ts.map +0 -1
- package/dist/etherscan.js +0 -109
- package/dist/etherscan.js.map +0 -1
- package/dist/external-transactions.d.ts +0 -10
- package/dist/external-transactions.d.ts.map +0 -1
- package/dist/external-transactions.js +0 -36
- package/dist/external-transactions.js.map +0 -1
- package/dist/history.d.ts +0 -15
- package/dist/history.d.ts.map +0 -1
- package/dist/history.js +0 -75
- package/dist/history.js.map +0 -1
- package/dist/mocks/txsMock.d.ts +0 -64
- package/dist/mocks/txsMock.d.ts.map +0 -1
- package/dist/mocks/txsMock.js +0 -515
- package/dist/mocks/txsMock.js.map +0 -1
- package/dist/transaction-type.d.ts +0 -14
- package/dist/transaction-type.d.ts.map +0 -1
- package/dist/transaction-type.js +0 -114
- package/dist/transaction-type.js.map +0 -1
- package/dist/utils.d.ts +0 -72
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -235
- package/dist/utils.js.map +0 -1
package/dist/transaction-type.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.determineTransactionType = exports.ESTIMATE_GAS_ERROR = void 0;
|
|
13
|
-
const abi_1 = require("@ethersproject/abi");
|
|
14
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
15
|
-
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
16
|
-
const types_1 = require("./types");
|
|
17
|
-
exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
18
|
-
const ERC20Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC20);
|
|
19
|
-
const ERC721Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC721);
|
|
20
|
-
const ERC1155Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC1155);
|
|
21
|
-
/**
|
|
22
|
-
* Determines the type of the transaction by analyzing the txParams.
|
|
23
|
-
* It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these
|
|
24
|
-
* represent specific events that we specify manually at transaction creation.
|
|
25
|
-
*
|
|
26
|
-
* @param txParams - Parameters for the transaction.
|
|
27
|
-
* @param ethQuery - EthQuery instance.
|
|
28
|
-
* @returns A object with the transaction type and the contract code response in Hex.
|
|
29
|
-
*/
|
|
30
|
-
function determineTransactionType(txParams, ethQuery) {
|
|
31
|
-
var _a;
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const { data, to } = txParams;
|
|
34
|
-
const name = (_a = parseStandardTokenTransactionData(data)) === null || _a === void 0 ? void 0 : _a.name;
|
|
35
|
-
if (data && !to) {
|
|
36
|
-
return { type: types_1.TransactionType.deployContract, getCodeResponse: undefined };
|
|
37
|
-
}
|
|
38
|
-
const { contractCode: resultCode, isContractAddress } = yield readAddressAsContract(ethQuery, to);
|
|
39
|
-
if (!isContractAddress) {
|
|
40
|
-
return { type: types_1.TransactionType.simpleSend, getCodeResponse: resultCode };
|
|
41
|
-
}
|
|
42
|
-
const hasValue = txParams.value && Number(txParams.value) !== 0;
|
|
43
|
-
const tokenMethodName = [
|
|
44
|
-
types_1.TransactionType.tokenMethodApprove,
|
|
45
|
-
types_1.TransactionType.tokenMethodSetApprovalForAll,
|
|
46
|
-
types_1.TransactionType.tokenMethodTransfer,
|
|
47
|
-
types_1.TransactionType.tokenMethodTransferFrom,
|
|
48
|
-
types_1.TransactionType.tokenMethodSafeTransferFrom,
|
|
49
|
-
].find((methodName) => methodName.toLowerCase() === (name === null || name === void 0 ? void 0 : name.toLowerCase()));
|
|
50
|
-
if (data && tokenMethodName && !hasValue) {
|
|
51
|
-
return { type: tokenMethodName, getCodeResponse: resultCode };
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
type: types_1.TransactionType.contractInteraction,
|
|
55
|
-
getCodeResponse: resultCode,
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
exports.determineTransactionType = determineTransactionType;
|
|
60
|
-
/**
|
|
61
|
-
* Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.
|
|
62
|
-
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
63
|
-
* contract standards
|
|
64
|
-
*
|
|
65
|
-
* @param data - Encoded transaction data.
|
|
66
|
-
* @returns A representation of an ethereum contract call.
|
|
67
|
-
*/
|
|
68
|
-
function parseStandardTokenTransactionData(data) {
|
|
69
|
-
if (!data) {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
return ERC20Interface.parseTransaction({ data });
|
|
74
|
-
}
|
|
75
|
-
catch (_a) {
|
|
76
|
-
// ignore and next try to parse with erc721 ABI
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
return ERC721Interface.parseTransaction({ data });
|
|
80
|
-
}
|
|
81
|
-
catch (_b) {
|
|
82
|
-
// ignore and next try to parse with erc1155 ABI
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
return ERC1155Interface.parseTransaction({ data });
|
|
86
|
-
}
|
|
87
|
-
catch (_c) {
|
|
88
|
-
// ignore and return undefined
|
|
89
|
-
}
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Reads an Ethereum address and determines if it is a contract address.
|
|
94
|
-
*
|
|
95
|
-
* @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.
|
|
96
|
-
* @param address - The Ethereum address.
|
|
97
|
-
* @returns An object containing the contract code and a boolean indicating if it is a contract address.
|
|
98
|
-
*/
|
|
99
|
-
function readAddressAsContract(ethQuery, address) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
let contractCode;
|
|
102
|
-
try {
|
|
103
|
-
contractCode = yield (0, controller_utils_1.query)(ethQuery, 'getCode', [address]);
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
contractCode = null;
|
|
107
|
-
}
|
|
108
|
-
const isContractAddress = contractCode
|
|
109
|
-
? contractCode !== '0x' && contractCode !== '0x0'
|
|
110
|
-
: false;
|
|
111
|
-
return { contractCode, isContractAddress };
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
//# sourceMappingURL=transaction-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-type.js","sourceRoot":"","sources":["../src/transaction-type.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,4CAA+C;AAC/C,iEAAmD;AAEnD,mEAA8E;AAG9E,mCAA0C;AAE7B,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,MAAM,cAAc,GAAG,IAAI,eAAS,CAAC,4BAAQ,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,eAAS,CAAC,6BAAS,CAAC,CAAC;AACjD,MAAM,gBAAgB,GAAG,IAAI,eAAS,CAAC,8BAAU,CAAC,CAAC;AAEnD;;;;;;;;GAQG;A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AED;;;;;;;GAOG;AACH,SAAS,iCAAiC,CACxC,IAAa;IAEb,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,SAAS,CAAC;KAClB;IAED,IAAI;QACF,OAAO,cAAc,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KAClD;IAAC,WAAM;QACN,+CAA+C;KAChD;IAED,IAAI;QACF,OAAO,eAAe,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KACnD;IAAC,WAAM;QACN,gDAAgD;KACjD;IAED,IAAI;QACF,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;KACpD;IAAC,WAAM;QACN,8BAA8B;KAC/B;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,SAAe,qBAAqB,CAClC,QAAkB,EAClB,OAAgB;;QAKhB,IAAI,YAAY,CAAC;QACjB,IAAI;YACF,YAAY,GAAG,MAAM,IAAA,wBAAK,EAAC,QAAQ,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;SAC5D;QAAC,OAAO,CAAC,EAAE;YACV,YAAY,GAAG,IAAI,CAAC;SACrB;QAED,MAAM,iBAAiB,GAAG,YAAY;YACpC,CAAC,CAAC,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,KAAK;YACjD,CAAC,CAAC,KAAK,CAAC;QACV,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAC7C,CAAC;CAAA","sourcesContent":["import type { TransactionDescription } from '@ethersproject/abi';\nimport { Interface } from '@ethersproject/abi';\nimport { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { abiERC721, abiERC20, abiERC1155 } from '@metamask/metamask-eth-abis';\n\nimport type { InferTransactionTypeResult, TransactionParams } from './types';\nimport { TransactionType } from './types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst ERC20Interface = new Interface(abiERC20);\nconst ERC721Interface = new Interface(abiERC721);\nconst ERC1155Interface = new Interface(abiERC1155);\n\n/**\n * Determines the type of the transaction by analyzing the txParams.\n * It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these\n * represent specific events that we specify manually at transaction creation.\n *\n * @param txParams - Parameters for the transaction.\n * @param ethQuery - EthQuery instance.\n * @returns A object with the transaction type and the contract code response in Hex.\n */\nexport async function determineTransactionType(\n txParams: TransactionParams,\n ethQuery: EthQuery,\n): Promise<InferTransactionTypeResult> {\n const { data, to } = txParams;\n const name = parseStandardTokenTransactionData(data)?.name;\n\n if (data && !to) {\n return { type: TransactionType.deployContract, getCodeResponse: undefined };\n }\n\n const { contractCode: resultCode, isContractAddress } =\n await readAddressAsContract(ethQuery, to);\n\n if (!isContractAddress) {\n return { type: TransactionType.simpleSend, getCodeResponse: resultCode };\n }\n\n const hasValue = txParams.value && Number(txParams.value) !== 0;\n\n const tokenMethodName = [\n TransactionType.tokenMethodApprove,\n TransactionType.tokenMethodSetApprovalForAll,\n TransactionType.tokenMethodTransfer,\n TransactionType.tokenMethodTransferFrom,\n TransactionType.tokenMethodSafeTransferFrom,\n ].find((methodName) => methodName.toLowerCase() === name?.toLowerCase());\n\n if (data && tokenMethodName && !hasValue) {\n return { type: tokenMethodName, getCodeResponse: resultCode };\n }\n\n return {\n type: TransactionType.contractInteraction,\n getCodeResponse: resultCode,\n };\n}\n\n/**\n * Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.\n * The data will decode correctly if the transaction is an interaction with a contract that matches one of these\n * contract standards\n *\n * @param data - Encoded transaction data.\n * @returns A representation of an ethereum contract call.\n */\nfunction parseStandardTokenTransactionData(\n data?: string,\n): TransactionDescription | undefined {\n if (!data) {\n return undefined;\n }\n\n try {\n return ERC20Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc721 ABI\n }\n\n try {\n return ERC721Interface.parseTransaction({ data });\n } catch {\n // ignore and next try to parse with erc1155 ABI\n }\n\n try {\n return ERC1155Interface.parseTransaction({ data });\n } catch {\n // ignore and return undefined\n }\n\n return undefined;\n}\n\n/**\n * Reads an Ethereum address and determines if it is a contract address.\n *\n * @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.\n * @param address - The Ethereum address.\n * @returns An object containing the contract code and a boolean indicating if it is a contract address.\n */\nasync function readAddressAsContract(\n ethQuery: EthQuery,\n address?: string,\n): Promise<{\n contractCode: string | null;\n isContractAddress: boolean;\n}> {\n let contractCode;\n try {\n contractCode = await query(ethQuery, 'getCode', [address]);\n } catch (e) {\n contractCode = null;\n }\n\n const isContractAddress = contractCode\n ? contractCode !== '0x' && contractCode !== '0x0'\n : false;\n return { contractCode, isContractAddress };\n}\n"]}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { Transaction as NonceTrackerTransaction } from 'nonce-tracker/dist/NonceTracker';
|
|
2
|
-
import { Transaction, FetchAllOptions, GasPriceValue, FeeMarketEIP1559Values, TransactionStatus } from './TransactionController';
|
|
3
|
-
import type { TransactionMeta } from './TransactionController';
|
|
4
|
-
export declare const ESTIMATE_GAS_ERROR = "eth_estimateGas rpc method error";
|
|
5
|
-
/**
|
|
6
|
-
* Return a URL that can be used to fetch ETH transactions.
|
|
7
|
-
*
|
|
8
|
-
* @param networkType - Network type of desired network.
|
|
9
|
-
* @param urlParams - The parameters used to construct the URL.
|
|
10
|
-
* @returns URL to fetch the access the endpoint.
|
|
11
|
-
*/
|
|
12
|
-
export declare function getEtherscanApiUrl(networkType: string, urlParams: any): string;
|
|
13
|
-
/**
|
|
14
|
-
* Normalizes properties on a Transaction object.
|
|
15
|
-
*
|
|
16
|
-
* @param transaction - Transaction object to normalize.
|
|
17
|
-
* @returns Normalized Transaction object.
|
|
18
|
-
*/
|
|
19
|
-
export declare function normalizeTransaction(transaction: Transaction): Transaction;
|
|
20
|
-
/**
|
|
21
|
-
* Validates a Transaction object for required properties and throws in
|
|
22
|
-
* the event of any validation error.
|
|
23
|
-
*
|
|
24
|
-
* @param transaction - Transaction object to validate.
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateTransaction(transaction: Transaction): void;
|
|
27
|
-
/**
|
|
28
|
-
* Checks if a transaction is EIP-1559 by checking for the existence of
|
|
29
|
-
* maxFeePerGas and maxPriorityFeePerGas within its parameters.
|
|
30
|
-
*
|
|
31
|
-
* @param transaction - Transaction object to add.
|
|
32
|
-
* @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
|
|
33
|
-
*/
|
|
34
|
-
export declare const isEIP1559Transaction: (transaction: Transaction) => boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Handles the fetch of incoming transactions.
|
|
37
|
-
*
|
|
38
|
-
* @param networkType - Network type of desired network.
|
|
39
|
-
* @param address - Address to get the transactions from.
|
|
40
|
-
* @param txHistoryLimit - The maximum number of transactions to fetch.
|
|
41
|
-
* @param opt - Object that can contain fromBlock and Etherscan service API key.
|
|
42
|
-
* @returns Responses for both ETH and ERC20 token transactions.
|
|
43
|
-
*/
|
|
44
|
-
export declare function handleTransactionFetch(networkType: string, address: string, txHistoryLimit: number, opt?: FetchAllOptions): Promise<[{
|
|
45
|
-
[result: string]: [];
|
|
46
|
-
}, {
|
|
47
|
-
[result: string]: [];
|
|
48
|
-
}]>;
|
|
49
|
-
export declare const validateGasValues: (gasValues: GasPriceValue | FeeMarketEIP1559Values) => void;
|
|
50
|
-
export declare const isFeeMarketEIP1559Values: (gasValues?: GasPriceValue | FeeMarketEIP1559Values | undefined) => gasValues is FeeMarketEIP1559Values;
|
|
51
|
-
export declare const isGasPriceValue: (gasValues?: GasPriceValue | FeeMarketEIP1559Values | undefined) => gasValues is GasPriceValue;
|
|
52
|
-
export declare const getIncreasedPriceHex: (value: number, rate: number) => string;
|
|
53
|
-
export declare const getIncreasedPriceFromExisting: (value: string | undefined, rate: number) => string;
|
|
54
|
-
/**
|
|
55
|
-
* Validates that the proposed value is greater than or equal to the minimum value.
|
|
56
|
-
*
|
|
57
|
-
* @param proposed - The proposed value.
|
|
58
|
-
* @param min - The minimum value.
|
|
59
|
-
* @returns The proposed value.
|
|
60
|
-
* @throws Will throw if the proposed value is too low.
|
|
61
|
-
*/
|
|
62
|
-
export declare function validateMinimumIncrease(proposed: string, min: string): string;
|
|
63
|
-
/**
|
|
64
|
-
* Helper function to filter and format transactions for the nonce tracker.
|
|
65
|
-
*
|
|
66
|
-
* @param fromAddress - Address of the account from which the transactions to filter from are sent.
|
|
67
|
-
* @param transactionStatus - Status of the transactions for which to filter.
|
|
68
|
-
* @param transactions - Array of transactionMeta objects that have been prefiltered.
|
|
69
|
-
* @returns Array of transactions formatted for the nonce tracker.
|
|
70
|
-
*/
|
|
71
|
-
export declare function getAndFormatTransactionsForNonceTracker(fromAddress: string, transactionStatus: TransactionStatus, transactions: TransactionMeta[]): NonceTrackerTransaction[];
|
|
72
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,IAAI,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAiBrE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,GAAG,GACb,MAAM,CAeR;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,eAS5D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,QAmD3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,gBAAiB,WAAW,KAAG,OAO/D,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,CAAC;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,CAAA;CAAE,EAAE;IAAE,CAAC,MAAM,EAAE,MAAM,GAAG,EAAE,CAAA;CAAE,CAAC,CAAC,CA8C/D;AAED,eAAO,MAAM,iBAAiB,cACjB,aAAa,GAAG,sBAAsB,SAUlD,CAAC;AAEF,eAAO,MAAM,wBAAwB,yGAIsC,CAAC;AAE5E,eAAO,MAAM,eAAe,gGAG0B,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"}
|
package/dist/utils.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getAndFormatTransactionsForNonceTracker = exports.validateMinimumIncrease = exports.getIncreasedPriceFromExisting = exports.getIncreasedPriceHex = exports.isGasPriceValue = exports.isFeeMarketEIP1559Values = exports.validateGasValues = exports.handleTransactionFetch = exports.isEIP1559Transaction = exports.validateTransaction = exports.normalizeTransaction = exports.getEtherscanApiUrl = exports.ESTIMATE_GAS_ERROR = void 0;
|
|
13
|
-
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
14
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
15
|
-
exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
16
|
-
const NORMALIZERS = {
|
|
17
|
-
data: (data) => (0, ethereumjs_util_1.addHexPrefix)(data),
|
|
18
|
-
from: (from) => (0, ethereumjs_util_1.addHexPrefix)(from).toLowerCase(),
|
|
19
|
-
gas: (gas) => (0, ethereumjs_util_1.addHexPrefix)(gas),
|
|
20
|
-
gasPrice: (gasPrice) => (0, ethereumjs_util_1.addHexPrefix)(gasPrice),
|
|
21
|
-
nonce: (nonce) => (0, ethereumjs_util_1.addHexPrefix)(nonce),
|
|
22
|
-
to: (to) => (0, ethereumjs_util_1.addHexPrefix)(to).toLowerCase(),
|
|
23
|
-
value: (value) => (0, ethereumjs_util_1.addHexPrefix)(value),
|
|
24
|
-
maxFeePerGas: (maxFeePerGas) => (0, ethereumjs_util_1.addHexPrefix)(maxFeePerGas),
|
|
25
|
-
maxPriorityFeePerGas: (maxPriorityFeePerGas) => (0, ethereumjs_util_1.addHexPrefix)(maxPriorityFeePerGas),
|
|
26
|
-
estimatedBaseFee: (maxPriorityFeePerGas) => (0, ethereumjs_util_1.addHexPrefix)(maxPriorityFeePerGas),
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Return a URL that can be used to fetch ETH transactions.
|
|
30
|
-
*
|
|
31
|
-
* @param networkType - Network type of desired network.
|
|
32
|
-
* @param urlParams - The parameters used to construct the URL.
|
|
33
|
-
* @returns URL to fetch the access the endpoint.
|
|
34
|
-
*/
|
|
35
|
-
function getEtherscanApiUrl(networkType, urlParams) {
|
|
36
|
-
let etherscanSubdomain = 'api';
|
|
37
|
-
if (networkType !== controller_utils_1.NetworkType.mainnet) {
|
|
38
|
-
etherscanSubdomain = `api-${networkType}`;
|
|
39
|
-
}
|
|
40
|
-
const apiUrl = `https://${etherscanSubdomain}.etherscan.io`;
|
|
41
|
-
let url = `${apiUrl}/api?`;
|
|
42
|
-
for (const paramKey in urlParams) {
|
|
43
|
-
if (urlParams[paramKey]) {
|
|
44
|
-
url += `${paramKey}=${urlParams[paramKey]}&`;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
url += 'tag=latest&page=1';
|
|
48
|
-
return url;
|
|
49
|
-
}
|
|
50
|
-
exports.getEtherscanApiUrl = getEtherscanApiUrl;
|
|
51
|
-
/**
|
|
52
|
-
* Normalizes properties on a Transaction object.
|
|
53
|
-
*
|
|
54
|
-
* @param transaction - Transaction object to normalize.
|
|
55
|
-
* @returns Normalized Transaction object.
|
|
56
|
-
*/
|
|
57
|
-
function normalizeTransaction(transaction) {
|
|
58
|
-
const normalizedTransaction = { from: '' };
|
|
59
|
-
let key;
|
|
60
|
-
for (key in NORMALIZERS) {
|
|
61
|
-
if (transaction[key]) {
|
|
62
|
-
normalizedTransaction[key] = NORMALIZERS[key](transaction[key]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return normalizedTransaction;
|
|
66
|
-
}
|
|
67
|
-
exports.normalizeTransaction = normalizeTransaction;
|
|
68
|
-
/**
|
|
69
|
-
* Validates a Transaction object for required properties and throws in
|
|
70
|
-
* the event of any validation error.
|
|
71
|
-
*
|
|
72
|
-
* @param transaction - Transaction object to validate.
|
|
73
|
-
*/
|
|
74
|
-
function validateTransaction(transaction) {
|
|
75
|
-
if (!transaction.from ||
|
|
76
|
-
typeof transaction.from !== 'string' ||
|
|
77
|
-
!(0, controller_utils_1.isValidHexAddress)(transaction.from)) {
|
|
78
|
-
throw new Error(`Invalid "from" address: ${transaction.from} must be a valid string.`);
|
|
79
|
-
}
|
|
80
|
-
if (transaction.to === '0x' || transaction.to === undefined) {
|
|
81
|
-
if (transaction.data) {
|
|
82
|
-
delete transaction.to;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
throw new Error(`Invalid "to" address: ${transaction.to} must be a valid string.`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else if (transaction.to !== undefined &&
|
|
89
|
-
!(0, controller_utils_1.isValidHexAddress)(transaction.to)) {
|
|
90
|
-
throw new Error(`Invalid "to" address: ${transaction.to} must be a valid string.`);
|
|
91
|
-
}
|
|
92
|
-
if (transaction.value !== undefined) {
|
|
93
|
-
const value = transaction.value.toString();
|
|
94
|
-
if (value.includes('-')) {
|
|
95
|
-
throw new Error(`Invalid "value": ${value} is not a positive number.`);
|
|
96
|
-
}
|
|
97
|
-
if (value.includes('.')) {
|
|
98
|
-
throw new Error(`Invalid "value": ${value} number must be denominated in wei.`);
|
|
99
|
-
}
|
|
100
|
-
const intValue = parseInt(transaction.value, 10);
|
|
101
|
-
const isValid = Number.isFinite(intValue) &&
|
|
102
|
-
!Number.isNaN(intValue) &&
|
|
103
|
-
!isNaN(Number(value)) &&
|
|
104
|
-
Number.isSafeInteger(intValue);
|
|
105
|
-
if (!isValid) {
|
|
106
|
-
throw new Error(`Invalid "value": ${value} number must be a valid number.`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.validateTransaction = validateTransaction;
|
|
111
|
-
/**
|
|
112
|
-
* Checks if a transaction is EIP-1559 by checking for the existence of
|
|
113
|
-
* maxFeePerGas and maxPriorityFeePerGas within its parameters.
|
|
114
|
-
*
|
|
115
|
-
* @param transaction - Transaction object to add.
|
|
116
|
-
* @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
|
|
117
|
-
*/
|
|
118
|
-
const isEIP1559Transaction = (transaction) => {
|
|
119
|
-
const hasOwnProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
120
|
-
return (hasOwnProp(transaction, 'maxFeePerGas') &&
|
|
121
|
-
hasOwnProp(transaction, 'maxPriorityFeePerGas'));
|
|
122
|
-
};
|
|
123
|
-
exports.isEIP1559Transaction = isEIP1559Transaction;
|
|
124
|
-
/**
|
|
125
|
-
* Handles the fetch of incoming transactions.
|
|
126
|
-
*
|
|
127
|
-
* @param networkType - Network type of desired network.
|
|
128
|
-
* @param address - Address to get the transactions from.
|
|
129
|
-
* @param txHistoryLimit - The maximum number of transactions to fetch.
|
|
130
|
-
* @param opt - Object that can contain fromBlock and Etherscan service API key.
|
|
131
|
-
* @returns Responses for both ETH and ERC20 token transactions.
|
|
132
|
-
*/
|
|
133
|
-
function handleTransactionFetch(networkType, address, txHistoryLimit, opt) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
// transactions
|
|
136
|
-
const urlParams = {
|
|
137
|
-
module: 'account',
|
|
138
|
-
address,
|
|
139
|
-
startBlock: opt === null || opt === void 0 ? void 0 : opt.fromBlock,
|
|
140
|
-
apikey: opt === null || opt === void 0 ? void 0 : opt.etherscanApiKey,
|
|
141
|
-
offset: txHistoryLimit.toString(),
|
|
142
|
-
order: 'desc',
|
|
143
|
-
};
|
|
144
|
-
const etherscanTxUrl = getEtherscanApiUrl(networkType, Object.assign(Object.assign({}, urlParams), { action: 'txlist' }));
|
|
145
|
-
const etherscanTxResponsePromise = (0, controller_utils_1.handleFetch)(etherscanTxUrl);
|
|
146
|
-
// tokens
|
|
147
|
-
const etherscanTokenUrl = getEtherscanApiUrl(networkType, Object.assign(Object.assign({}, urlParams), { action: 'tokentx' }));
|
|
148
|
-
const etherscanTokenResponsePromise = (0, controller_utils_1.handleFetch)(etherscanTokenUrl);
|
|
149
|
-
let [etherscanTxResponse, etherscanTokenResponse] = yield Promise.all([
|
|
150
|
-
etherscanTxResponsePromise,
|
|
151
|
-
etherscanTokenResponsePromise,
|
|
152
|
-
]);
|
|
153
|
-
if (etherscanTxResponse.status === '0' ||
|
|
154
|
-
etherscanTxResponse.result.length <= 0) {
|
|
155
|
-
etherscanTxResponse = { status: etherscanTxResponse.status, result: [] };
|
|
156
|
-
}
|
|
157
|
-
if (etherscanTokenResponse.status === '0' ||
|
|
158
|
-
etherscanTokenResponse.result.length <= 0) {
|
|
159
|
-
etherscanTokenResponse = {
|
|
160
|
-
status: etherscanTokenResponse.status,
|
|
161
|
-
result: [],
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return [etherscanTxResponse, etherscanTokenResponse];
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
exports.handleTransactionFetch = handleTransactionFetch;
|
|
168
|
-
const validateGasValues = (gasValues) => {
|
|
169
|
-
Object.keys(gasValues).forEach((key) => {
|
|
170
|
-
const value = gasValues[key];
|
|
171
|
-
if (typeof value !== 'string' || !(0, ethereumjs_util_1.isHexString)(value)) {
|
|
172
|
-
throw new TypeError(`expected hex string for ${key} but received: ${value}`);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
exports.validateGasValues = validateGasValues;
|
|
177
|
-
const isFeeMarketEIP1559Values = (gasValues) => (gasValues === null || gasValues === void 0 ? void 0 : gasValues.maxFeePerGas) !== undefined ||
|
|
178
|
-
(gasValues === null || gasValues === void 0 ? void 0 : gasValues.maxPriorityFeePerGas) !== undefined;
|
|
179
|
-
exports.isFeeMarketEIP1559Values = isFeeMarketEIP1559Values;
|
|
180
|
-
const isGasPriceValue = (gasValues) => (gasValues === null || gasValues === void 0 ? void 0 : gasValues.gasPrice) !== undefined;
|
|
181
|
-
exports.isGasPriceValue = isGasPriceValue;
|
|
182
|
-
const getIncreasedPriceHex = (value, rate) => (0, ethereumjs_util_1.addHexPrefix)(`${parseInt(`${value * rate}`, 10).toString(16)}`);
|
|
183
|
-
exports.getIncreasedPriceHex = getIncreasedPriceHex;
|
|
184
|
-
const getIncreasedPriceFromExisting = (value, rate) => {
|
|
185
|
-
return (0, exports.getIncreasedPriceHex)((0, controller_utils_1.convertHexToDecimal)(value), rate);
|
|
186
|
-
};
|
|
187
|
-
exports.getIncreasedPriceFromExisting = getIncreasedPriceFromExisting;
|
|
188
|
-
/**
|
|
189
|
-
* Validates that the proposed value is greater than or equal to the minimum value.
|
|
190
|
-
*
|
|
191
|
-
* @param proposed - The proposed value.
|
|
192
|
-
* @param min - The minimum value.
|
|
193
|
-
* @returns The proposed value.
|
|
194
|
-
* @throws Will throw if the proposed value is too low.
|
|
195
|
-
*/
|
|
196
|
-
function validateMinimumIncrease(proposed, min) {
|
|
197
|
-
const proposedDecimal = (0, controller_utils_1.convertHexToDecimal)(proposed);
|
|
198
|
-
const minDecimal = (0, controller_utils_1.convertHexToDecimal)(min);
|
|
199
|
-
if (proposedDecimal >= minDecimal) {
|
|
200
|
-
return proposed;
|
|
201
|
-
}
|
|
202
|
-
const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;
|
|
203
|
-
throw new Error(errorMsg);
|
|
204
|
-
}
|
|
205
|
-
exports.validateMinimumIncrease = validateMinimumIncrease;
|
|
206
|
-
/**
|
|
207
|
-
* Helper function to filter and format transactions for the nonce tracker.
|
|
208
|
-
*
|
|
209
|
-
* @param fromAddress - Address of the account from which the transactions to filter from are sent.
|
|
210
|
-
* @param transactionStatus - Status of the transactions for which to filter.
|
|
211
|
-
* @param transactions - Array of transactionMeta objects that have been prefiltered.
|
|
212
|
-
* @returns Array of transactions formatted for the nonce tracker.
|
|
213
|
-
*/
|
|
214
|
-
function getAndFormatTransactionsForNonceTracker(fromAddress, transactionStatus, transactions) {
|
|
215
|
-
return transactions
|
|
216
|
-
.filter(({ status, transaction: { from } }) => status === transactionStatus &&
|
|
217
|
-
from.toLowerCase() === fromAddress.toLowerCase())
|
|
218
|
-
.map(({ status, transaction: { from, gas, value, nonce } }) => {
|
|
219
|
-
// the only value we care about is the nonce
|
|
220
|
-
// but we need to return the other values to satisfy the type
|
|
221
|
-
// TODO: refactor nonceTracker to not require this
|
|
222
|
-
return {
|
|
223
|
-
status,
|
|
224
|
-
history: [{}],
|
|
225
|
-
txParams: {
|
|
226
|
-
from: from !== null && from !== void 0 ? from : '',
|
|
227
|
-
gas: gas !== null && gas !== void 0 ? gas : '',
|
|
228
|
-
value: value !== null && value !== void 0 ? value : '',
|
|
229
|
-
nonce: nonce !== null && nonce !== void 0 ? nonce : '',
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
exports.getAndFormatTransactionsForNonceTracker = getAndFormatTransactionsForNonceTracker;
|
|
235
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA4D;AAC5D,iEAKoC;AAWvB,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,MAAM,WAAW,GAA0C;IACzD,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,8BAAY,EAAC,IAAI,CAAC;IAC1C,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,8BAAY,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE;IACxD,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,8BAAY,EAAC,GAAG,CAAC;IACvC,QAAQ,EAAE,CAAC,QAAgB,EAAE,EAAE,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AU,EAAE;QACjC,OAAO,QAAQ,CAAC;KACjB;IACD,MAAM,QAAQ,GAAG,uBAAuB,eAAe,6CAA6C,UAAU,EAAE,CAAC;IACjH,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC;AARD,0DAQC;AAED;;;;;;;GAOG;AACH,SAAgB,uCAAuC,CACrD,WAAmB,EACnB,iBAAoC,EACpC,YAA+B;IAE/B,OAAO,YAAY;SAChB,MAAM,CACL,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CACpC,MAAM,KAAK,iBAAiB;QAC5B,IAAI,CAAC,WAAW,EAAE,KAAK,WAAW,CAAC,WAAW,EAAE,CACnD;SACA,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;QAC5D,4CAA4C;QAC5C,6DAA6D;QAC7D,kDAAkD;QAClD,OAAO;YACL,MAAM;YACN,OAAO,EAAE,CAAC,EAAE,CAAC;YACb,QAAQ,EAAE;gBACR,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE;gBAChB,GAAG,EAAE,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,EAAE;gBACd,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE;gBAClB,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE;aACnB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AA1BD,0FA0BC","sourcesContent":["import { addHexPrefix, isHexString } from 'ethereumjs-util';\nimport {\n NetworkType,\n convertHexToDecimal,\n handleFetch,\n isValidHexAddress,\n} from '@metamask/controller-utils';\nimport type { Transaction as NonceTrackerTransaction } from 'nonce-tracker/dist/NonceTracker';\nimport {\n Transaction,\n FetchAllOptions,\n GasPriceValue,\n FeeMarketEIP1559Values,\n TransactionStatus,\n} from './TransactionController';\nimport type { TransactionMeta } from './TransactionController';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\nconst NORMALIZERS: { [param in keyof Transaction]: any } = {\n data: (data: string) => addHexPrefix(data),\n from: (from: string) => addHexPrefix(from).toLowerCase(),\n gas: (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 * Return a URL that can be used to fetch ETH transactions.\n *\n * @param networkType - Network type of desired network.\n * @param urlParams - The parameters used to construct the URL.\n * @returns URL to fetch the access the endpoint.\n */\nexport function getEtherscanApiUrl(\n networkType: string,\n urlParams: any,\n): string {\n let etherscanSubdomain = 'api';\n if (networkType !== NetworkType.mainnet) {\n etherscanSubdomain = `api-${networkType}`;\n }\n const apiUrl = `https://${etherscanSubdomain}.etherscan.io`;\n let url = `${apiUrl}/api?`;\n\n for (const paramKey in urlParams) {\n if (urlParams[paramKey]) {\n url += `${paramKey}=${urlParams[paramKey]}&`;\n }\n }\n url += 'tag=latest&page=1';\n return url;\n}\n\n/**\n * Normalizes properties on a Transaction object.\n *\n * @param transaction - Transaction object to normalize.\n * @returns Normalized Transaction object.\n */\nexport function normalizeTransaction(transaction: Transaction) {\n const normalizedTransaction: Transaction = { from: '' };\n let key: keyof Transaction;\n for (key in NORMALIZERS) {\n if (transaction[key as keyof Transaction]) {\n normalizedTransaction[key] = NORMALIZERS[key](transaction[key]) as never;\n }\n }\n return normalizedTransaction;\n}\n\n/**\n * Validates a Transaction object for required properties and throws in\n * the event of any validation error.\n *\n * @param transaction - Transaction object to validate.\n */\nexport function validateTransaction(transaction: Transaction) {\n if (\n !transaction.from ||\n typeof transaction.from !== 'string' ||\n !isValidHexAddress(transaction.from)\n ) {\n throw new Error(\n `Invalid \"from\" address: ${transaction.from} must be a valid string.`,\n );\n }\n\n if (transaction.to === '0x' || transaction.to === undefined) {\n if (transaction.data) {\n delete transaction.to;\n } else {\n throw new Error(\n `Invalid \"to\" address: ${transaction.to} must be a valid string.`,\n );\n }\n } else if (\n transaction.to !== undefined &&\n !isValidHexAddress(transaction.to)\n ) {\n throw new Error(\n `Invalid \"to\" address: ${transaction.to} must be a valid string.`,\n );\n }\n\n if (transaction.value !== undefined) {\n const value = transaction.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(transaction.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 transaction - Transaction 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 = (transaction: Transaction): boolean => {\n const hasOwnProp = (obj: Transaction, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(transaction, 'maxFeePerGas') &&\n hasOwnProp(transaction, 'maxPriorityFeePerGas')\n );\n};\n\n/**\n * Handles the fetch of incoming transactions.\n *\n * @param networkType - Network type of desired network.\n * @param address - Address to get the transactions from.\n * @param txHistoryLimit - The maximum number of transactions to fetch.\n * @param opt - Object that can contain fromBlock and Etherscan service API key.\n * @returns Responses for both ETH and ERC20 token transactions.\n */\nexport async function handleTransactionFetch(\n networkType: string,\n address: string,\n txHistoryLimit: number,\n opt?: FetchAllOptions,\n): Promise<[{ [result: string]: [] }, { [result: string]: [] }]> {\n // transactions\n const urlParams = {\n module: 'account',\n address,\n startBlock: opt?.fromBlock,\n apikey: opt?.etherscanApiKey,\n offset: txHistoryLimit.toString(),\n order: 'desc',\n };\n const etherscanTxUrl = getEtherscanApiUrl(networkType, {\n ...urlParams,\n action: 'txlist',\n });\n const etherscanTxResponsePromise = handleFetch(etherscanTxUrl);\n\n // tokens\n const etherscanTokenUrl = getEtherscanApiUrl(networkType, {\n ...urlParams,\n action: 'tokentx',\n });\n const etherscanTokenResponsePromise = handleFetch(etherscanTokenUrl);\n\n let [etherscanTxResponse, etherscanTokenResponse] = await Promise.all([\n etherscanTxResponsePromise,\n etherscanTokenResponsePromise,\n ]);\n\n if (\n etherscanTxResponse.status === '0' ||\n etherscanTxResponse.result.length <= 0\n ) {\n etherscanTxResponse = { status: etherscanTxResponse.status, result: [] };\n }\n\n if (\n etherscanTokenResponse.status === '0' ||\n etherscanTokenResponse.result.length <= 0\n ) {\n etherscanTokenResponse = {\n status: etherscanTokenResponse.status,\n result: [],\n };\n }\n\n return [etherscanTxResponse, etherscanTokenResponse];\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, transaction: { from } }) =>\n status === transactionStatus &&\n from.toLowerCase() === fromAddress.toLowerCase(),\n )\n .map(({ status, transaction: { 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"]}
|