diff --git a/.eslintrc.js b/.eslintrc.js index 4c4b31c736..b4d34c088e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,6 +14,44 @@ module.exports = { { files: ['*.test.ts', '*.test.js'], extends: ['@metamask/eslint-config-jest'], + rules: { + 'jsdoc/check-access': 'off', + 'jsdoc/check-alignment': 'off', + 'jsdoc/check-line-alignment': 'off', + 'jsdoc/check-param-names': 'off', + 'jsdoc/check-property-names': 'off', + 'jsdoc/check-tag-names': 'off', + 'jsdoc/check-types': 'off', + 'jsdoc/check-values': 'off', + 'jsdoc/empty-tags': 'off', + 'jsdoc/implements-on-classes': 'off', + 'jsdoc/match-description': 'off', + 'jsdoc/multiline-blocks': 'off', + 'jsdoc/newline-after-description': 'off', + 'jsdoc/no-bad-blocks': 'off', + 'jsdoc/no-defaults': 'off', + 'jsdoc/no-multi-asterisks': 'off', + 'jsdoc/require-asterisk-prefix': 'off', + 'jsdoc/require-description': 'off', + 'jsdoc/require-hyphen-before-param-description': 'off', + 'jsdoc/require-jsdoc': 'off', + 'jsdoc/require-param-name': 'off', + 'jsdoc/require-param': 'off', + 'jsdoc/require-param-description': 'off', + 'jsdoc/require-param-type': 'off', + 'jsdoc/require-property': 'off', + 'jsdoc/require-property-description': 'off', + 'jsdoc/require-property-name': 'off', + 'jsdoc/require-property-type': 'off', + 'jsdoc/require-returns': 'off', + 'jsdoc/require-returns-check': 'off', + 'jsdoc/require-returns-description': 'off', + 'jsdoc/require-returns-type': 'off', + 'jsdoc/require-yields': 'off', + 'jsdoc/require-yields-check': 'off', + 'jsdoc/tag-lines': 'off', + 'jsdoc/valid-types': 'off', + }, }, { files: ['*.js'], diff --git a/src/gas/fetchFeeHistory.ts b/src/gas/fetchFeeHistory.ts index 62cb4f1c19..15ee6303da 100644 --- a/src/gas/fetchFeeHistory.ts +++ b/src/gas/fetchFeeHistory.ts @@ -9,7 +9,6 @@ type HexString = `0x${string}`; * * Historical data for gas and priority fees for a range of blocks within a * particular network. This can be used to gauge how congested the network is. - * * @property {string} startBlockId - The id of the oldest block in the block * range requested (as hex). * @property {Array} blocks - Data for the blocks in the block @@ -25,7 +24,6 @@ type FeeHistory = { * @type BlockFeeHistory * * Historical data for gas and priority fees for a block. - * * @property {Array} baseFeePerGas - The base fee per gas for the block. * @property {Array} gasUsedRatio - A number between 0 and 1 that * represents the ratio between the effective gas used and the gas limit for @@ -53,36 +51,36 @@ type EthFeeHistoryResponse = { }; }; -function hexToDec(hex: string): any { +/** + * Converts a hexadecimal string to a decimal number (as a BN instance). + * + * @param hex - A string encoding a hexadecimal number (with a "0x") prefix. + * @returns The BN instance. + */ +function hexToDec(hex: string): BN { return new BN(new BN(stripHexPrefix(hex), 16).toString(10), 10); } /** - * Uses eth_feeHistory (an EIP-1559 feature) to obtain information about gas and - * priority fees from a range of blocks that appeared on a network, starting - * from a particular block and working backward in time. This can be used to - * gauge how congested the network is. + * Uses eth_feeHistory (an EIP-1559 feature) to obtain information about gas and priority fees from + * a range of blocks that appeared on a network, starting from a particular block and working + * backward in time. This can be used to gauge how congested the network is. * * @param args - The arguments. - * @param args.ethQuery - An EthQuery instance that wraps a provider for the - * network in question. - * @param args.endBlock - Which block to start with when forming the block - * range. Can be a block tag ("latest" for the latest successful block or - * "pending" for the latest pending block) or a block id. - * @param args.numberOfBlocks - How many blocks to jump back from the endBlock when - * forming the block range. Each array in the return value will be of this - * length. - * @param args.percentiles - A tuple of numbers between 1 and 100 which will - * advise how priorityFeesByPercentile in the return value will be formed. When - * Ethereum runs the eth_feeHistory method, for each block it is considering, it - * will calculate the ratio of gas used for each transaction compared to the - * total gas used for the block, then sort all transactions in the block by this - * ratio. For each percentile given, it will then find the transaction whose gas - * used ratio matches the percentile and capture that transaction's priority fee. - * Hence, priorityFeesByPercentile represents the priority fees of transactions - * at key gas used ratios. - * - * @return Promise + * @param args.ethQuery - An EthQuery instance that wraps a provider for the network in question. + * @param args.endBlock - Which block to start with when forming the block range. Can be a block tag + * ("latest" for the latest successful block or "pending" for the latest pending block) or a block + * id. + * @param args.numberOfBlocks - How many blocks to jump back from the endBlock when forming the + * block range. Each array in the return value will be of this length. + * @param args.percentiles - A tuple of numbers between 1 and 100 which will advise how + * priorityFeesByPercentile in the return value will be formed. When Ethereum runs the + * eth_feeHistory method, for each block it is considering, it will calculate the ratio of gas used + * for each transaction compared to the total gas used for the block, then sort all transactions in + * the block by this ratio. For each percentile given, it will then find the transaction whose gas + * used ratio matches the percentile and capture that transaction's priority fee. Hence, + * priorityFeesByPercentile represents the priority fees of transactions at key gas used ratios. + * @returns The fee history data. */ export async function fetchFeeHistory({ ethQuery, diff --git a/src/util.ts b/src/util.ts index 040daa8631..9631fe5826 100644 --- a/src/util.ts +++ b/src/util.ts @@ -768,6 +768,17 @@ export function validateMinimumIncrease(proposed: string, min: string) { throw new Error(errorMsg); } +/** + * Rotates a matrix. That is, takes an array of tuples (arrays) representing rows and columns and + * reorients that array such that rows becomes columns and vice versa. Each row is expected to have + * the same number of columns, although if that is not the case, then the final result will have the + * same number of columns per row, where values may be filled in with undefined. + * + * @param args - The arguments. + * @param args.tuples - The tuples on which we want to operate. + * @param args.numberOfColumnsPerTuple - The number of columns you expected each row to have. + * @returns The rotated array of arrays. + */ export function zipEqualSizedTuples({ tuples, numberOfColumnsPerTuple,