Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@types/ethereumjs-util": "^6.1.0",
"@metamask/ethjs-query": "0.5.3",
"@types/jest": "^26.0.22",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^5.42.1",
Expand Down Expand Up @@ -68,20 +68,15 @@
"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"
},
"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
}
}
}
10 changes: 5 additions & 5 deletions src/swapsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) };
}

/**
Expand Down
66 changes: 48 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -1425,13 +1462,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"
Expand Down Expand Up @@ -3344,17 +3374,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"
Expand All @@ -3381,6 +3400,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"
Expand Down