Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove @metamask/ethjs package #29620

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 29 additions & 15 deletions app/scripts/lib/ens-ipfs/resolver.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import namehash from 'eth-ens-namehash';
import Eth from '@metamask/ethjs-query';
import EthContract from '@metamask/ethjs-contract';
import contentHash from '@ensdomains/content-hash';
import { Web3Provider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import registryAbi from './contracts/registry';
import resolverAbi from './contracts/resolver';

export default async function resolveEnsToIpfsContentId({ provider, name }) {
const eth = new Eth(provider);
const hash = namehash.hash(name);
const contract = new EthContract(eth);

// lookup registry
const chainId = Number.parseInt(await eth.net_version(), 10);
const chainId = Number.parseInt(
await provider.request({ method: 'net_version' }),
10,
);
const registryAddress = getRegistryForChainId(chainId);
if (!registryAddress) {
throw new Error(
`EnsIpfsResolver - no known ens-ipfs registry for chainId "${chainId}"`,
);
}
const Registry = contract(registryAbi).at(registryAddress);
const web3Provider = new Web3Provider(provider);
const registryContract = new Contract(
registryAddress,
registryAbi,
web3Provider,
);
// lookup resolver
const resolverLookupResult = await Registry.resolver(hash);
const resolverAddress = resolverLookupResult[0];
const resolverAddress = await registryContract.resolver(hash);
if (hexValueIsEmpty(resolverAddress)) {
throw new Error(`EnsIpfsResolver - no resolver found for name "${name}"`);
}
const Resolver = contract(resolverAbi).at(resolverAddress);
const resolverContract = new Contract(
resolverAddress,
resolverAbi,
web3Provider,
);

const isEIP1577Compliant = await Resolver.supportsInterface('0xbc1c58d1');
const isLegacyResolver = await Resolver.supportsInterface('0xd8389dc5');
if (isEIP1577Compliant[0]) {
const contentLookupResult = await Resolver.contenthash(hash);
const isEIP1577Compliant = await resolverContract.supportsInterface(
'0xbc1c58d1',
);
const isLegacyResolver = await resolverContract.supportsInterface(
'0xd8389dc5',
);
if (isEIP1577Compliant) {
const contentLookupResult = await resolverContract.contenthash(hash);
const rawContentHash = contentLookupResult[0];
let decodedContentHash = contentHash.decode(rawContentHash);
const type = contentHash.getCodec(rawContentHash);
Expand All @@ -41,9 +55,9 @@ export default async function resolveEnsToIpfsContentId({ provider, name }) {

return { type, hash: decodedContentHash };
}
if (isLegacyResolver[0]) {
if (isLegacyResolver) {
// lookup content id
const contentLookupResult = await Resolver.content(hash);
const contentLookupResult = await resolverContract.content(hash);
const content = contentLookupResult[0];
if (hexValueIsEmpty(content)) {
throw new Error(
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EthQuery, { Provider } from '@metamask/eth-query';
import type { Provider } from '@metamask/network-controller';
import { FetchGasFeeEstimateOptions } from '@metamask/gas-fee-controller';
import { BigNumber } from 'bignumber.js';
import { isHexString } from 'ethereumjs-util';
Expand Down Expand Up @@ -799,15 +799,14 @@ async function buildEventFragmentProperties({
id,
userFeeLevel,
} = transactionMeta;
const query = new EthQuery(transactionMetricsRequest.provider);
const source = referrer === ORIGIN_METAMASK ? 'user' : 'dapp';

const gasFeeSelected =
userFeeLevel === 'dappSuggested' ? 'dapp_proposed' : userFeeLevel;

const { assetType, tokenStandard } = await determineTransactionAssetType(
transactionMeta,
query,
transactionMetricsRequest.provider,
transactionMetricsRequest.getTokenStandardAndDetails,
);

Expand Down
16 changes: 4 additions & 12 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import LatticeKeyring from 'eth-lattice-keyring';
import { rawChainData } from 'eth-chainlist';
import { MetaMaskKeyring as QRHardwareKeyring } from '@keystonehq/metamask-airgapped-keyring';
import EthQuery from '@metamask/eth-query';
import EthJSQuery from '@metamask/ethjs-query';
import { nanoid } from 'nanoid';
import { captureException } from '@sentry/browser';
import { AddressBookController } from '@metamask/address-book-controller';
Expand Down Expand Up @@ -5400,18 +5399,11 @@ export default class MetamaskController extends EventEmitter {
}

async estimateGas(estimateGasParams) {
return new Promise((resolve, reject) => {
return new EthJSQuery(this.provider).estimateGas(
estimateGasParams,
(err, res) => {
if (err) {
return reject(err);
}

return resolve(res.toString(16));
},
);
const result = await this.provider.request({
method: 'eth_estimateGas',
params: [estimateGasParams],
});
return result.toString(16);
Comment on lines +5402 to +5406
Copy link
Contributor

@MajorLift MajorLift Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a breaking change for estimateGas which is exposed externally via the getApi method.

As an async function, estimateGas should still return a promise, but the error handling behavior using reject appears to have been dropped entirely.

Can we expect the provider.request method to catch any exceptions, or should we manually implement error handling so that the error information is accessible from the return value of estimateGas like it is in the existing code?

}

handleWatchAssetRequest = ({ asset, type, origin, networkClientId }) => {
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'react-devtools';
import PortStream from 'extension-port-stream';
import browser from 'webextension-polyfill';

import Eth from '@metamask/ethjs';
import EthQuery from '@metamask/eth-query';
import StreamProvider from 'web3-stream-provider';
import log from 'loglevel';
Expand Down Expand Up @@ -363,7 +362,6 @@ function setupWeb3Connection(connectionStream) {
providerStream.on('error', console.error.bind(console));
global.ethereumProvider = providerStream;
global.ethQuery = new EthQuery(providerStream);
global.eth = new Eth(providerStream);
}

/**
Expand Down
107 changes: 39 additions & 68 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
"ethers>@ethersproject/keccak256": {
"packages": {
"@ethersproject/bytes": true,
"@metamask/ethjs>js-sha3": true
"eth-ens-namehash>js-sha3": true
}
},
"ethers>@ethersproject/logger": {
Expand Down Expand Up @@ -965,7 +965,7 @@
},
"packages": {
"@ethereumjs/tx>@ethereumjs/util": true,
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/controller-utils>@metamask/ethjs-unit": true,
"@metamask/utils": true,
"@metamask/controller-utils>@spruceid/siwe-parser": true,
"bn.js": true,
Expand Down Expand Up @@ -1193,8 +1193,8 @@
"packages": {
"@babel/runtime": true,
"@metamask/eth-token-tracker>@metamask/eth-block-tracker": true,
"@metamask/ethjs-contract": true,
"@metamask/ethjs-query": true,
"eth-method-registry>@metamask/ethjs-contract": true,
"eth-method-registry>@metamask/ethjs-query": true,
"@metamask/safe-event-emitter": true,
"bn.js": true,
"@metamask/eth-token-tracker>deep-equal": true,
Expand All @@ -1221,80 +1221,56 @@
"URL": true
}
},
"@metamask/ethjs": {
"globals": {
"clearInterval": true,
"setInterval": true
},
"packages": {
"@metamask/ethjs-contract": true,
"@metamask/ethjs>@metamask/ethjs-filter": true,
"@metamask/ethjs>@metamask/ethjs-provider-http": true,
"@metamask/ethjs-query": true,
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/ethjs>@metamask/ethjs-util": true,
"@metamask/ethjs>@metamask/number-to-bn": true,
"bn.js": true,
"browserify>buffer": true,
"@metamask/ethjs>ethjs-abi": true,
"@metamask/ethjs>js-sha3": true
}
},
"@metamask/ethjs-contract": {
"eth-method-registry>@metamask/ethjs-contract": {
"packages": {
"@babel/runtime": true,
"@metamask/ethjs>@metamask/ethjs-filter": true,
"@metamask/ethjs>@metamask/ethjs-util": true,
"@metamask/ethjs>ethjs-abi": true,
"@metamask/ethjs>js-sha3": true,
"eth-method-registry>@metamask/ethjs-contract>@metamask/ethjs-filter": true,
"eth-method-registry>@metamask/ethjs-contract>@metamask/ethjs-util": true,
"eth-method-registry>@metamask/ethjs-contract>ethjs-abi": true,
"eth-ens-namehash>js-sha3": true,
"promise-to-callback": true
}
},
"@metamask/ethjs>@metamask/ethjs-filter": {
"eth-method-registry>@metamask/ethjs-contract>@metamask/ethjs-filter": {
"globals": {
"clearInterval": true,
"setInterval": true
}
},
"@metamask/ethjs-query>@metamask/ethjs-format": {
"packages": {
"@metamask/ethjs>@metamask/ethjs-util": true,
"@metamask/ethjs>@metamask/number-to-bn": true,
"@metamask/ethjs-query>@metamask/ethjs-format>ethjs-schema": true,
"@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true
}
},
"@metamask/ethjs>@metamask/ethjs-provider-http": {
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format": {
"packages": {
"@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": true
"eth-method-registry>@metamask/ethjs-contract>@metamask/ethjs-util": true,
"@metamask/controller-utils>@metamask/ethjs-unit>@metamask/number-to-bn": true,
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>ethjs-schema": true,
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true
}
},
"@metamask/ethjs-query": {
"eth-method-registry>@metamask/ethjs-query": {
"globals": {
"console": true
},
"packages": {
"@metamask/ethjs-query>@metamask/ethjs-format": true,
"@metamask/ethjs-query>@metamask/ethjs-rpc": true,
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format": true,
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-rpc": true,
"promise-to-callback": true
}
},
"@metamask/ethjs-query>@metamask/ethjs-rpc": {
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-rpc": {
"packages": {
"promise-to-callback": true
}
},
"@metamask/ethjs>@metamask/ethjs-unit": {
"@metamask/controller-utils>@metamask/ethjs-unit": {
"packages": {
"@metamask/ethjs>@metamask/number-to-bn": true,
"@metamask/controller-utils>@metamask/ethjs-unit>@metamask/number-to-bn": true,
"bn.js": true
}
},
"@metamask/ethjs>@metamask/ethjs-util": {
"eth-method-registry>@metamask/ethjs-contract>@metamask/ethjs-util": {
"packages": {
"browserify>buffer": true,
"@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true,
"@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true,
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true
}
},
"@metamask/gas-fee-controller": {
Expand Down Expand Up @@ -1486,10 +1462,10 @@
"uuid": true
}
},
"@metamask/ethjs>@metamask/number-to-bn": {
"@metamask/controller-utils>@metamask/ethjs-unit>@metamask/number-to-bn": {
"packages": {
"bn.js": true,
"@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true
}
},
"@metamask/object-multiplex": {
Expand Down Expand Up @@ -3593,7 +3569,7 @@
"packages": {
"bn.js": true,
"buffer": true,
"@metamask/ethjs>js-sha3": true
"eth-ens-namehash>js-sha3": true
}
},
"eth-ens-namehash": {
Expand All @@ -3603,7 +3579,7 @@
"packages": {
"browserify>buffer": true,
"eth-ens-namehash>idna-uts46-hx": true,
"@metamask/ethjs>js-sha3": true
"eth-ens-namehash>js-sha3": true
}
},
"eth-lattice-keyring": {
Expand All @@ -3628,8 +3604,8 @@
},
"eth-method-registry": {
"packages": {
"@metamask/ethjs-contract": true,
"@metamask/ethjs-query": true
"eth-method-registry>@metamask/ethjs-contract": true,
"eth-method-registry>@metamask/ethjs-query": true
}
},
"@ethereumjs/tx>ethereum-cryptography": {
Expand Down Expand Up @@ -3780,12 +3756,12 @@
"ethers>@ethersproject/wordlists": true
}
},
"@metamask/ethjs>ethjs-abi": {
"eth-method-registry>@metamask/ethjs-contract>ethjs-abi": {
"packages": {
"bn.js": true,
"browserify>buffer": true,
"@metamask/ethjs>js-sha3": true,
"@metamask/ethjs>ethjs-abi>number-to-bn": true
"eth-ens-namehash>js-sha3": true,
"eth-method-registry>@metamask/ethjs-contract>ethjs-abi>number-to-bn": true
}
},
"webpack>events": {
Expand Down Expand Up @@ -3911,7 +3887,7 @@
"eth-lattice-keyring>gridplus-sdk>elliptic": true,
"eth-lattice-keyring>gridplus-sdk>eth-eip712-util-browser": true,
"ethers>@ethersproject/sha2>hash.js": true,
"@metamask/ethjs>js-sha3": true,
"eth-ens-namehash>js-sha3": true,
"lodash": true,
"eth-lattice-keyring>rlp": true,
"ganache>secp256k1": true,
Expand Down Expand Up @@ -4132,7 +4108,7 @@
"browserify>buffer": true
}
},
"@metamask/ethjs>js-sha3": {
"eth-ens-namehash>js-sha3": {
"globals": {
"define": true
},
Expand Down Expand Up @@ -4474,10 +4450,10 @@
"fetch": true
}
},
"@metamask/ethjs>ethjs-abi>number-to-bn": {
"eth-method-registry>@metamask/ethjs-contract>ethjs-abi>number-to-bn": {
"packages": {
"bn.js": true,
"@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true
}
},
"string.prototype.matchall>es-abstract>object-inspect": {
Expand Down Expand Up @@ -5311,9 +5287,9 @@
"koa>content-disposition>safe-buffer": true
}
},
"@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": {
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": {
"packages": {
"@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true
"eth-method-registry>@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true
}
},
"react-markdown>style-to-object": {
Expand Down Expand Up @@ -5602,11 +5578,6 @@
"string.prototype.matchall>es-abstract>gopd": true,
"koa>is-generator-function>has-tostringtag": true
}
},
"@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": {
"globals": {
"XMLHttpRequest": true
}
}
}
}
Loading
Loading