Skip to content

Commit

Permalink
deps: Bump @metamask/{eth-json-rpc-provider,rpc-errors} (#1653)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Elliot Winkler <[email protected]>
  • Loading branch information
legobeat and mcmire authored Oct 11, 2023
1 parent d53d83a commit 2e95c89
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 140 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/eth-json-rpc-provider": "^1.0.0",
"@metamask/eth-json-rpc-provider": "^2.1.0",
"@metamask/json-rpc-engine": "^7.1.1",
"@metamask/utils": "^8.1.0",
"@types/node": "^16.18.54",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand All @@ -57,10 +58,9 @@
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eth-block-tracker": "^7.0.1",
"eth-block-tracker": "^8.0.0",
"execa": "^5.0.0",
"isomorphic-fetch": "^3.0.0",
"json-rpc-engine": "^6.1.0",
"nock": "^13.3.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.4.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/approval-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@metamask/base-controller": "^3.2.3",
"@metamask/rpc-errors": "^6.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/utils": "^8.1.0",
"immer": "^9.0.6",
"nanoid": "^3.1.31"
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@metamask/metamask-eth-abis": "3.0.0",
"@metamask/network-controller": "^14.0.0",
"@metamask/preferences-controller": "^4.4.2",
"@metamask/rpc-errors": "^6.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/utils": "^8.1.0",
"@types/uuid": "^8.3.0",
"async-mutex": "^0.2.6",
Expand Down
3 changes: 3 additions & 0 deletions packages/gas-fee-controller/src/GasFeeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export class GasFeeController extends PollingController<
this.legacyAPIEndpoint = legacyAPIEndpoint;
this.clientId = clientId;

// @ts-expect-error TODO: Provider type alignment
this.ethQuery = new EthQuery(this.#getProvider());

if (onNetworkStateChange && getChainId) {
Expand Down Expand Up @@ -417,6 +418,7 @@ export class GasFeeController extends PollingController<
isEIP1559Compatible = false;
}

// @ts-expect-error TODO: Provider type alignment
const ethQuery = new EthQuery(networkClient.provider);

const gasFeeCalculations = await determineGasFeeCalculations({
Expand Down Expand Up @@ -588,6 +590,7 @@ export class GasFeeController extends PollingController<
const newChainId = networkControllerState.providerConfig.chainId;

if (newChainId !== this.currentChainId) {
// @ts-expect-error TODO: Provider type alignment
this.ethQuery = new EthQuery(this.#getProvider());
await this.resetPolling();

Expand Down
12 changes: 6 additions & 6 deletions packages/network-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
"dependencies": {
"@metamask/base-controller": "^3.2.3",
"@metamask/controller-utils": "^5.0.2",
"@metamask/eth-json-rpc-infura": "^8.1.1",
"@metamask/eth-json-rpc-middleware": "^11.0.2",
"@metamask/eth-json-rpc-provider": "^1.0.0",
"@metamask/eth-json-rpc-infura": "^9.0.0",
"@metamask/eth-json-rpc-middleware": "^12.0.0",
"@metamask/eth-json-rpc-provider": "^2.1.0",
"@metamask/eth-query": "^3.0.1",
"@metamask/json-rpc-engine": "^7.1.1",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/swappable-obj-proxy": "^2.1.0",
"@metamask/utils": "^8.1.0",
"async-mutex": "^0.2.6",
"eth-block-tracker": "^7.0.1",
"eth-rpc-errors": "^4.0.2",
"eth-block-tracker": "^8.0.0",
"immer": "^9.0.6",
"json-rpc-engine": "^6.1.0",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isSafeChainId,
} from '@metamask/controller-utils';
import EthQuery from '@metamask/eth-query';
import { errorCodes } from '@metamask/rpc-errors';
import { createEventEmitterProxy } from '@metamask/swappable-obj-proxy';
import type { SwappableProxy } from '@metamask/swappable-obj-proxy';
import type { Hex } from '@metamask/utils';
Expand All @@ -18,7 +19,6 @@ import {
isPlainObject,
} from '@metamask/utils';
import { strict as assert } from 'assert';
import { errorCodes } from 'eth-rpc-errors';
import type { Patch } from 'immer';
import { v4 as random } from 'uuid';

Expand Down Expand Up @@ -980,6 +980,7 @@ export class NetworkController extends BaseControllerV2<
}

const networkClient = this.getNetworkClientById(networkClientId);
// @ts-expect-error TODO: Provider type alignment
const ethQuery = new EthQuery(networkClient.provider);

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1545,6 +1546,7 @@ export class NetworkController extends BaseControllerV2<
});
}

// @ts-expect-error TODO: Provider type alignment
this.#ethQuery = new EthQuery(this.#providerProxy);
}
}
16 changes: 8 additions & 8 deletions packages/network-controller/src/create-network-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import {
providerFromEngine,
providerFromMiddleware,
} from '@metamask/eth-json-rpc-provider';
import type { Hex } from '@metamask/utils';
import { PollingBlockTracker } from 'eth-block-tracker';
import {
createAsyncMiddleware,
createScaffoldMiddleware,
JsonRpcEngine,
mergeMiddleware,
} from 'json-rpc-engine';
import type { JsonRpcMiddleware } from 'json-rpc-engine';
} from '@metamask/json-rpc-engine';
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import type { Hex, Json, JsonRpcParams } from '@metamask/utils';
import { PollingBlockTracker } from 'eth-block-tracker';

import type {
BlockTracker,
Expand Down Expand Up @@ -126,7 +126,7 @@ function createInfuraNetworkMiddleware({
blockTracker: PollingBlockTracker;
network: InfuraNetworkType;
rpcProvider: SafeEventEmitterProvider;
rpcApiMiddleware: JsonRpcMiddleware<unknown, unknown>;
rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;
}) {
return mergeMiddleware([
createNetworkAndChainIdMiddleware({ network }),
Expand Down Expand Up @@ -158,7 +158,7 @@ function createNetworkAndChainIdMiddleware({

const createChainIdMiddleware = (
chainId: Hex,
): JsonRpcMiddleware<unknown, unknown> => {
): JsonRpcMiddleware<JsonRpcParams, Json> => {
return (req, res, next, end) => {
if (req.method === 'eth_chainId') {
res.result = chainId;
Expand All @@ -184,8 +184,8 @@ function createCustomNetworkMiddleware({
}: {
blockTracker: PollingBlockTracker;
chainId: Hex;
rpcApiMiddleware: any;
}) {
rpcApiMiddleware: JsonRpcMiddleware<JsonRpcParams, Json>;
}): JsonRpcMiddleware<JsonRpcParams, Json> {
// eslint-disable-next-line n/no-process-env
const testMiddlewares = process.env.IN_TEST
? [createEstimateGasDelayTestMiddleware()]
Expand Down
6 changes: 4 additions & 2 deletions packages/network-controller/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { InfuraNetworkType } from '@metamask/controller-utils';
import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider';
import type { Hex } from '@metamask/utils';
import type { PollingBlockTracker } from 'eth-block-tracker';
import type { BlockTracker as BaseBlockTracker } from 'eth-block-tracker';

export type Provider = SafeEventEmitterProvider;

export type BlockTracker = PollingBlockTracker;
export type BlockTracker = BaseBlockTracker & {
checkForLatestBlock(): Promise<string>;
};

/**
* The type of network client that can be created.
Expand Down
24 changes: 12 additions & 12 deletions packages/network-controller/tests/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
NetworkType,
toHex,
} from '@metamask/controller-utils';
import { rpcErrors } from '@metamask/rpc-errors';
import assert from 'assert';
import { ethErrors } from 'eth-rpc-errors';
import type { Patch } from 'immer';
import { when, resetAllWhenMocks } from 'jest-when';
import { inspect, isDeepStrictEqual, promisify } from 'util';
Expand All @@ -27,7 +27,7 @@ import type {
ProviderConfig,
} from '../src/NetworkController';
import { NetworkController } from '../src/NetworkController';
import type { Provider } from '../src/types';
import type { BlockTracker, Provider } from '../src/types';
import { NetworkClientType } from '../src/types';
import type { FakeProviderStub } from './fake-provider';
import { FakeProvider } from './fake-provider';
Expand Down Expand Up @@ -128,15 +128,15 @@ const SUCCESSFUL_ETH_GET_BLOCK_BY_NUMBER_RESPONSE = {
/**
* A response object for a request that has been geoblocked by Infura.
*/
const BLOCKED_INFURA_JSON_RPC_ERROR = ethErrors.rpc.internal(
const BLOCKED_INFURA_JSON_RPC_ERROR = rpcErrors.internal(
JSON.stringify({ error: 'countryBlocked' }),
);

/**
* A response object for a unsuccessful request to any RPC method. It is assumed
* that the error here is insignificant to the test.
*/
const GENERIC_JSON_RPC_ERROR = ethErrors.rpc.internal(
const GENERIC_JSON_RPC_ERROR = rpcErrors.internal(
JSON.stringify({ error: 'oops' }),
);

Expand Down Expand Up @@ -5106,7 +5106,7 @@ describe('NetworkController', () => {
request: {
method: 'eth_getBlockByNumber',
},
error: ethErrors.rpc.methodNotFound(),
error: rpcErrors.methodNotFound(),
},
]),
buildFakeProvider([
Expand Down Expand Up @@ -5622,7 +5622,7 @@ describe('NetworkController', () => {
request: {
method: 'eth_getBlockByNumber',
},
error: ethErrors.rpc.methodNotFound(),
error: rpcErrors.methodNotFound(),
},
]),
buildFakeProvider([
Expand Down Expand Up @@ -6250,7 +6250,7 @@ function lookupNetworkTests({
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: ethErrors.rpc.limitExceeded('some error'),
error: rpcErrors.limitExceeded('some error'),
},
],
stubLookupNetworkWhileSetting: true,
Expand Down Expand Up @@ -6291,7 +6291,7 @@ function lookupNetworkTests({
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: ethErrors.rpc.limitExceeded('some error'),
error: rpcErrors.limitExceeded('some error'),
},
],
});
Expand Down Expand Up @@ -6326,7 +6326,7 @@ function lookupNetworkTests({
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: ethErrors.rpc.limitExceeded('some error'),
error: rpcErrors.limitExceeded('some error'),
},
],
stubLookupNetworkWhileSetting: true,
Expand Down Expand Up @@ -6358,7 +6358,7 @@ function lookupNetworkTests({
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: ethErrors.rpc.limitExceeded('some error'),
error: rpcErrors.limitExceeded('some error'),
},
],
stubLookupNetworkWhileSetting: true,
Expand Down Expand Up @@ -6392,7 +6392,7 @@ function lookupNetworkTests({
method: 'eth_getBlockByNumber',
params: ['latest', false],
},
error: ethErrors.rpc.limitExceeded('some error'),
error: rpcErrors.limitExceeded('some error'),
},
],
stubLookupNetworkWhileSetting: true,
Expand Down Expand Up @@ -6957,7 +6957,7 @@ function buildFakeClient(
rpcUrl: 'https://test.network',
},
provider,
blockTracker: new FakeBlockTracker(),
blockTracker: new FakeBlockTracker() as BlockTracker,
destroy: () => {
// do nothing
},
Expand Down
4 changes: 2 additions & 2 deletions packages/network-controller/tests/fake-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider/dist/safe-event-emitter-provider';
import type { JsonRpcRequest, JsonRpcResponse } from 'json-rpc-engine';
import { JsonRpcEngine } from 'json-rpc-engine';
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import type { JsonRpcRequest, JsonRpcResponse } from '@metamask/utils';
import { inspect, isDeepStrictEqual } from 'util';

// Store this in case it gets stubbed later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export async function withNetworkClient(

const { provider, blockTracker } = clientUnderTest;

// @ts-expect-error TODO: Provider type alignment
const ethQuery = new EthQuery(provider);
const curriedMakeRpcCall = (request: Request) =>
makeRpcCall(ethQuery, request);
Expand Down
2 changes: 1 addition & 1 deletion packages/permission-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@metamask/base-controller": "^3.2.3",
"@metamask/controller-utils": "^5.0.2",
"@metamask/json-rpc-engine": "^7.1.1",
"@metamask/rpc-errors": "^6.0.0",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/utils": "^8.1.0",
"@types/deep-freeze-strict": "^1.1.0",
"deep-freeze-strict": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/rate-limit-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@metamask/base-controller": "^3.2.3",
"eth-rpc-errors": "^4.0.2",
"@metamask/rpc-errors": "^6.1.0",
"immer": "^9.0.6"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/rate-limit-controller/src/RateLimitController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import { BaseControllerV2 as BaseController } from '@metamask/base-controller';
import { ethErrors } from 'eth-rpc-errors';
import { rpcErrors } from '@metamask/rpc-errors';
import type { Patch } from 'immer';

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ export class RateLimitController<
...args: Parameters<RateLimitedApis[ApiType]['method']>
): Promise<ReturnType<RateLimitedApis[ApiType]['method']>> {
if (this.isRateLimited(type, origin)) {
throw ethErrors.rpc.limitExceeded({
throw rpcErrors.limitExceeded({
message: `"${type.toString()}" is currently rate-limited. Please try again later.`,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/selected-network-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
},
"dependencies": {
"@metamask/base-controller": "^3.2.3",
"@metamask/network-controller": "^14.0.0",
"json-rpc-engine": "^6.1.0"
"@metamask/json-rpc-engine": "^7.1.1",
"@metamask/network-controller": "^14.0.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ControllerMessenger } from '@metamask/base-controller';
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import type {
NetworkClientId,
NetworkControllerGetStateAction,
} from '@metamask/network-controller';
import type { JsonRpcMiddleware } from 'json-rpc-engine';

import type {
SelectedNetworkControllerGetNetworkClientIdForDomainAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ControllerMessenger } from '@metamask/base-controller';
import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import type { NetworkControllerGetStateAction } from '@metamask/network-controller';
import { JsonRpcEngine } from 'json-rpc-engine';

import type {
SelectedNetworkControllerGetNetworkClientIdForDomainAction,
Expand Down
2 changes: 1 addition & 1 deletion packages/signature-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@metamask/controller-utils": "^5.0.2",
"@metamask/logging-controller": "^1.0.3",
"@metamask/message-manager": "^7.3.5",
"@metamask/rpc-errors": "^6.1.0",
"@metamask/utils": "^8.1.0",
"eth-rpc-errors": "^4.0.2",
"ethereumjs-util": "^7.0.10",
"immer": "^9.0.6",
"lodash": "^4.17.21"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
PersonalMessageManager,
TypedMessageManager,
} from '@metamask/message-manager';
import { EthereumProviderError } from 'eth-rpc-errors';
import { EthereumProviderError } from '@metamask/rpc-errors';

import type {
SignatureControllerMessenger,
Expand Down
Loading

0 comments on commit 2e95c89

Please sign in to comment.