From 2cfd0ef1367b7980cb73f9a26917e53478bb71d0 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Fri, 1 Dec 2023 01:18:39 +0000 Subject: [PATCH 1/3] deps: remove ethereumjs-util - replace `addHexPrefix` with `add0x` from `@metamask/utils` --- package.json | 2 -- src/swapsUtil.ts | 10 +++++----- yarn.lock | 29 +++++++++++------------------ 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 6fc23bb2..3e5ccbc3 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "@metamask/eslint-config-nodejs": "^12.1.0", "@metamask/eslint-config-typescript": "^12.1.0", "@metamask/ethjs-query": "0.5.3", - "@types/ethereumjs-util": "^6.1.0", "@types/jest": "^26.0.22", "@types/node": "^20.10.4", "@typescript-eslint/eslint-plugin": "^5.42.1", @@ -69,7 +68,6 @@ "abort-controller": "^3.0.0", "async-mutex": "^0.3.1", "bignumber.js": "^9.0.1", - "ethereumjs-util": "^7.0.10", "human-standard-token-abi": "^2.0.0", "web3": "^4.2.2" }, diff --git a/src/swapsUtil.ts b/src/swapsUtil.ts index 99fbd306..fdd07aeb 100644 --- a/src/swapsUtil.ts +++ b/src/swapsUtil.ts @@ -2,8 +2,8 @@ import { convertHexToDecimal } from '@metamask/controller-utils'; import type { Transaction } from '@metamask/controllers'; import { util } from '@metamask/controllers'; import type { Hex } from '@metamask/utils'; +import { add0x } from '@metamask/utils'; import { BigNumber } from 'bignumber.js'; -import { addHexPrefix } from 'ethereumjs-util'; import { ALLOWED_CONTRACT_ADDRESSES, @@ -381,11 +381,11 @@ export function calculateGasEstimateWithRefund( estimatedRefund: number | null, estimatedGas: string | null, ): BigNumber { - const estimated = estimatedGas && addHexPrefix(estimatedGas); + const estimated = estimatedGas ? add0x(estimatedGas) : '0x0'; const maxGasMinusRefund = new BigNumber(maxGas ?? MAX_GAS_LIMIT, 10).minus( estimatedRefund ?? 0, ); - const estimatedGasBN = new BigNumber(estimated ?? '0x0'); + const estimatedGasBN = new BigNumber(estimated); const gasEstimateWithRefund = maxGasMinusRefund.lt(estimatedGasBN) ? maxGasMinusRefund : estimatedGasBN; @@ -651,13 +651,13 @@ export async function estimateGas(transaction: Transaction, ethQuery: any) { ]); estimatedTransaction.data = !data ? data - : /* istanbul ignore next */ addHexPrefix(data); + : /* istanbul ignore next */ add0x(data); // 3. If this is a contract address, safely estimate gas using RPC estimatedTransaction.value = typeof value === 'undefined' ? '0x0' : /* istanbul ignore next */ value; const gasHex = await query(ethQuery, 'estimateGas', [estimatedTransaction]); - return { blockGasLimit: gasLimit, gas: addHexPrefix(gasHex) }; + return { blockGasLimit: gasLimit, gas: add0x(gasHex) }; } /** diff --git a/yarn.lock b/yarn.lock index 063372d8..2b7b2b1d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1461,13 +1461,6 @@ dependencies: "@types/ms" "*" -"@types/ethereumjs-util@^6.1.0": - version "6.1.0" - resolved "https://registry.yarnpkg.com/@types/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz#9dabd7302ec9728a7d99be15f4143977c33cd5ac" - integrity sha512-5N0RJldhKCKwDksdnuNHbEJuwO5pjEdtwdHj/kZLxaS84s5R1NLgYfAuDF/VZ4whYABJJvv+o0O8TXLm+F/Byw== - dependencies: - ethereumjs-util "*" - "@types/graceful-fs@^4.1.3": version "4.1.9" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.9.tgz#2a06bc0f68a20ab37b3e36aa238be6abdf49e8b4" @@ -3380,17 +3373,6 @@ ethereumjs-tx@^2.1.1: ethereumjs-common "^1.5.0" ethereumjs-util "^6.0.0" -ethereumjs-util@*, ethereumjs-util@^7.0.10, ethereumjs-util@^7.0.9, ethereumjs-util@^7.1.2, ethereumjs-util@^7.1.4, ethereumjs-util@^7.1.5: - version "7.1.5" - resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz#9ecf04861e4fbbeed7465ece5f23317ad1129181" - integrity sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg== - dependencies: - "@types/bn.js" "^5.1.0" - bn.js "^5.1.2" - create-hash "^1.1.2" - ethereum-cryptography "^0.1.3" - rlp "^2.2.4" - ethereumjs-util@^5.0.0, ethereumjs-util@^5.1.1, ethereumjs-util@^5.1.2, ethereumjs-util@^5.1.5: version "5.2.1" resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-5.2.1.tgz#a833f0e5fca7e5b361384dc76301a721f537bf65" @@ -3417,6 +3399,17 @@ ethereumjs-util@^6.0.0, ethereumjs-util@^6.2.1: ethjs-util "0.1.6" rlp "^2.2.3" +ethereumjs-util@^7.0.10, ethereumjs-util@^7.0.9, ethereumjs-util@^7.1.2, ethereumjs-util@^7.1.4, ethereumjs-util@^7.1.5: + version "7.1.5" + resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz#9ecf04861e4fbbeed7465ece5f23317ad1129181" + integrity sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg== + dependencies: + "@types/bn.js" "^5.1.0" + bn.js "^5.1.2" + create-hash "^1.1.2" + ethereum-cryptography "^0.1.3" + rlp "^2.2.4" + ethereumjs-vm@^2.3.4: version "2.6.0" resolved "https://registry.yarnpkg.com/ethereumjs-vm/-/ethereumjs-vm-2.6.0.tgz#76243ed8de031b408793ac33907fb3407fe400c6" From 7aabc36710ed4ce62b666e204c9b4871eda0fbb6 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Fri, 16 Feb 2024 10:27:30 +0000 Subject: [PATCH 2/3] update allow-scripts config --- package.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 3e5ccbc3..e73eb4f7 100644 --- a/package.json +++ b/package.json @@ -74,13 +74,9 @@ "lavamoat": { "allowScripts": { "@lavamoat/preinstall-always-fail": false, - "keccak": true, - "secp256k1": true, - "core-js": false, - "@metamask/controllers>@keystonehq/metamask-airgapped-keyring>@keystonehq/base-eth-keyring>hdkey>secp256k1": false, "@metamask/controllers>babel-runtime>core-js": false, - "ethereumjs-util>ethereum-cryptography>keccak": false, - "ethereumjs-util>ethereum-cryptography>secp256k1": false + "@metamask/controllers>ethereumjs-util>ethereum-cryptography>keccak": true, + "@metamask/controllers>ethereumjs-util>ethereum-cryptography>secp256k1": true } } } From 202d05e7530cd48859a2b4afd581e16ce469bde2 Mon Sep 17 00:00:00 2001 From: nikoferro Date: Tue, 16 Apr 2024 15:05:30 +0200 Subject: [PATCH 3/3] fix: yarn.lock --- yarn.lock | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/yarn.lock b/yarn.lock index 101c16e1..180de674 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1159,6 +1159,35 @@ tweetnacl "^1.0.3" tweetnacl-util "^0.15.1" +"@metamask/ethjs-format@^0.2.9": + version "0.2.9" + resolved "https://registry.yarnpkg.com/@metamask/ethjs-format/-/ethjs-format-0.2.9.tgz#f606390e7f9aa82ea6f179a3e0d7bd91ba49f483" + integrity sha512-jqtUTh/mqzUH/BIBLfnpjVse7zl428+Gnubn6EmAqJFk19PT7Nbw5X+FzvuDh3xkXXF0KXW1DNlxnfMDjrm3sg== + dependencies: + "@metamask/ethjs-util" "^0.2.0" + bn.js "4.11.6" + ethjs-schema "0.2.1" + is-hex-prefixed "1.0.0" + number-to-bn "1.7.0" + strip-hex-prefix "1.0.0" + +"@metamask/ethjs-query@0.5.3": + version "0.5.3" + resolved "https://registry.yarnpkg.com/@metamask/ethjs-query/-/ethjs-query-0.5.3.tgz#491a99668d2093fe945ec74f8bec3b75bfdaec2a" + integrity sha512-hSttg1b3CNzSiixFJjHc1B0JEbMag7RpGwUqReE3SDXfVQJvS8qR3GQhaI3nhMrD8nvXThxYPBxC5TLbGRqdTg== + dependencies: + "@metamask/ethjs-format" "^0.2.9" + "@metamask/ethjs-rpc" "0.3.0 || ^0.3.2" + babel-runtime "^6.26.0" + promise-to-callback "^1.0.0" + +"@metamask/ethjs-rpc@0.3.0 || ^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@metamask/ethjs-rpc/-/ethjs-rpc-0.3.2.tgz#9d5afe074b2dd8e71f05a1704ab76904a198db00" + integrity sha512-GnMq498r6zcWYfVpO4IdxX0kjFygVg/GP86TpAvTTi7WVhXH49u26f3/SH/F4ZWvoenWLyRdTGpkVFO82Aaz/A== + dependencies: + promise-to-callback "^1.0.0" + "@metamask/ethjs-unit@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@metamask/ethjs-unit/-/ethjs-unit-0.3.0.tgz#d44d21d3b4ad443fb0cdd0362ea07c6f51e68ec4" @@ -1167,6 +1196,14 @@ "@metamask/number-to-bn" "^1.7.1" bn.js "^5.2.1" +"@metamask/ethjs-util@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@metamask/ethjs-util/-/ethjs-util-0.2.0.tgz#4c39c772e69512d527a3bd54a80a0b08565b5983" + integrity sha512-i7kPlhnk2Doz7tQd90frh0WtrKS5FbYfQw2npYd3dVx5rhbvUjhyz7T/coVZSP3QDbszyzD3xmC50OxBmZou3Q== + dependencies: + is-hex-prefixed "1.0.0" + strip-hex-prefix "1.0.0" + "@metamask/metamask-eth-abis@3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@metamask/metamask-eth-abis/-/metamask-eth-abis-3.0.0.tgz#eccc0746b3ab1ab63000444403819c16e88b5272"