Skip to content

Commit

Permalink
Merge branch 'main' into caip-multichain-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Jan 17, 2025
2 parents d184228 + 0106a5f commit 6700c42
Show file tree
Hide file tree
Showing 33 changed files with 801 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
## Snaps Team
/packages/rate-limit-controller @MetaMask/snaps-devs

## Portfolio Team
/packages/token-search-discovery-controller @MetaMask/portfolio

## Wallet API Platform Team
/packages/multichain @MetaMask/wallet-api-platform-engineers
/packages/queued-request-controller @MetaMask/wallet-api-platform-engineers
Expand Down Expand Up @@ -100,3 +103,5 @@
/packages/transaction-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/user-operation-controller/package.json @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/user-operation-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/token-search-discovery-controller/package.json @MetaMask/portfolio @MetaMask/wallet-framework-engineers
/packages/token-search-discovery-controller/CHANGELOG.md @MetaMask/portfolio @MetaMask/wallet-framework-engineers
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Each package in this repository has its own README where you can find installati
- [`@metamask/rate-limit-controller`](packages/rate-limit-controller)
- [`@metamask/selected-network-controller`](packages/selected-network-controller)
- [`@metamask/signature-controller`](packages/signature-controller)
- [`@metamask/token-search-discovery-controller`](packages/token-search-discovery-controller)
- [`@metamask/transaction-controller`](packages/transaction-controller)
- [`@metamask/user-operation-controller`](packages/user-operation-controller)

Expand Down Expand Up @@ -91,8 +92,10 @@ linkStyle default opacity:0.5
profile_sync_controller(["@metamask/profile-sync-controller"]);
queued_request_controller(["@metamask/queued-request-controller"]);
rate_limit_controller(["@metamask/rate-limit-controller"]);
remote_feature_flag_controller(["@metamask/remote-feature-flag-controller"]);
selected_network_controller(["@metamask/selected-network-controller"]);
signature_controller(["@metamask/signature-controller"]);
token_search_discovery_controller(["@metamask/token-search-discovery-controller"]);
transaction_controller(["@metamask/transaction-controller"]);
user_operation_controller(["@metamask/user-operation-controller"]);
accounts_controller --> base_controller;
Expand Down Expand Up @@ -164,6 +167,8 @@ linkStyle default opacity:0.5
queued_request_controller --> network_controller;
queued_request_controller --> selected_network_controller;
rate_limit_controller --> base_controller;
remote_feature_flag_controller --> base_controller;
remote_feature_flag_controller --> controller_utils;
selected_network_controller --> base_controller;
selected_network_controller --> json_rpc_engine;
selected_network_controller --> network_controller;
Expand Down
7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import jest from '@metamask/eslint-config-jest';
import nodejs from '@metamask/eslint-config-nodejs';
import typescript from '@metamask/eslint-config-typescript';

const NODE_LTS_VERSION = 22;

const config = createConfig([
...base,
{
Expand Down Expand Up @@ -83,6 +85,11 @@ const config = createConfig([
'jest/prefer-lowercase-title': 'warn',
'jest/prefer-strict-equal': 'warn',
},
settings: {
node: {
version: `^${NODE_LTS_VERSION}`,
},
},
},
{
// These files are test helpers, not tests. We still use the Jest ESLint
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/core-monorepo",
"version": "283.0.0",
"version": "284.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
9 changes: 8 additions & 1 deletion packages/accounts-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [21.0.1]

### Changed

- Bump `@metamask/eth-snap-keyring` from `^8.0.0` to `^8.1.0` ([#5167](https://github.com/MetaMask/core/pull/5167))

## [21.0.0]

### Changed
Expand Down Expand Up @@ -388,7 +394,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release ([#1637](https://github.com/MetaMask/core/pull/1637))

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[21.0.1]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[21.0.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[20.0.2]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[20.0.1]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/accounts-controller",
"version": "21.0.0",
"version": "21.0.1",
"description": "Manages internal accounts",
"keywords": [
"MetaMask",
Expand Down Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@ethereumjs/util": "^8.1.0",
"@metamask/base-controller": "^7.1.1",
"@metamask/eth-snap-keyring": "^8.0.0",
"@metamask/eth-snap-keyring": "^8.1.0",
"@metamask/keyring-api": "^13.0.0",
"@metamask/keyring-internal-api": "^2.0.0",
"@metamask/snaps-sdk": "^6.7.0",
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 @@ -77,7 +77,7 @@
},
"devDependencies": {
"@babel/runtime": "^7.23.9",
"@metamask/accounts-controller": "^21.0.0",
"@metamask/accounts-controller": "^21.0.1",
"@metamask/approval-controller": "^7.1.2",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@metamask/eth-simple-keyring": "^6.0.5",
"@metamask/keyring-api": "^13.0.0",
"@metamask/keyring-internal-api": "^2.0.0",
"@metamask/message-manager": "^11.0.3",
"@metamask/message-manager": "^12.0.0",
"@metamask/utils": "^11.0.1",
"async-mutex": "^0.5.0",
"ethereumjs-wallet": "^1.0.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/message-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [12.0.0]

### Changed

- **BREAKING:** Base class of `DecryptMessageManager` and `EncryptionPublicKeyManager`(`AbstractMessageManager`) now expects new options to initialise ([#5103](https://github.com/MetaMask/core/pull/5103))
Expand Down Expand Up @@ -357,7 +359,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

All changes listed after this point were applied to this package following the monorepo conversion.

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[11.0.3]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[11.0.2]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[11.0.1]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion packages/message-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/message-manager",
"version": "11.0.3",
"version": "12.0.0",
"description": "Stores and manages interactions with signing requests",
"keywords": [
"MetaMask",
Expand Down
21 changes: 6 additions & 15 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { Hex } from '@metamask/utils';
import { hasProperty, isPlainObject, isStrictHexString } from '@metamask/utils';
import deepEqual from 'fast-deep-equal';
import type { Draft } from 'immer';
import { cloneDeep } from 'lodash';
import type { Logger } from 'loglevel';
import { createSelector } from 'reselect';
import * as URI from 'uri-js';
Expand Down Expand Up @@ -1636,11 +1637,6 @@ export class NetworkController extends BaseController<
});
});

this.#networkConfigurationsByNetworkClientId =
buildNetworkConfigurationsByNetworkClientId(
this.state.networkConfigurationsByChainId,
);

this.messagingSystem.publish(
`${controllerName}:networkAdded`,
newNetworkConfiguration,
Expand Down Expand Up @@ -1919,11 +1915,6 @@ export class NetworkController extends BaseController<
});
}

this.#networkConfigurationsByNetworkClientId =
buildNetworkConfigurationsByNetworkClientId(
this.state.networkConfigurationsByChainId,
);

this.#unregisterNetworkClientsAsNeeded({
networkClientOperations,
autoManagedNetworkClientRegistry,
Expand Down Expand Up @@ -1983,11 +1974,6 @@ export class NetworkController extends BaseController<
});
});

this.#networkConfigurationsByNetworkClientId =
buildNetworkConfigurationsByNetworkClientId(
this.state.networkConfigurationsByChainId,
);

this.messagingSystem.publish(
'NetworkController:networkRemoved',
existingNetworkConfiguration,
Expand Down Expand Up @@ -2500,6 +2486,11 @@ export class NetworkController extends BaseController<
state.networkConfigurationsByChainId[args.networkFields.chainId] =
args.networkConfigurationToPersist;
}

this.#networkConfigurationsByNetworkClientId =
buildNetworkConfigurationsByNetworkClientId(
cloneDeep(state.networkConfigurationsByChainId),
);
}

/**
Expand Down
54 changes: 54 additions & 0 deletions packages/network-controller/tests/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11338,6 +11338,60 @@ describe('NetworkController', () => {
});
});
});

it('allows calling `getNetworkConfigurationByNetworkClientId` when subscribing to state changes containing new endpoints', async () => {
const network = buildCustomNetworkConfiguration({
chainId: '0x1' as Hex,
name: 'mainnet',
nativeCurrency: 'ETH',
blockExplorerUrls: [],
defaultRpcEndpointIndex: 0,
rpcEndpoints: [
{
type: RpcEndpointType.Custom,
url: 'https://test.endpoint/1',
networkClientId: 'client1',
},
],
});

await withController(
{
state: {
selectedNetworkClientId: 'client1',
networkConfigurationsByChainId: { '0x1': network },
},
},
async ({ controller, messenger }) => {

const stateChangePromise = new Promise<NetworkConfiguration | undefined>((resolve) => {
messenger.subscribe('NetworkController:stateChange', (state) => {
const { networkClientId } =
state.networkConfigurationsByChainId['0x1'].rpcEndpoints[1];

resolve(
controller.getNetworkConfigurationByNetworkClientId(networkClientId),
);
});
});

// Add a new endpoint
await controller.updateNetwork('0x1', {
...network,
rpcEndpoints: [
...network.rpcEndpoints,
{
type: RpcEndpointType.Custom,
url: 'https://test.endpoint/2',
},
],
});

const networkConfiguration = await stateChangePromise;
expect(networkConfiguration).toBeDefined();
},
);
});
});

describe('removeNetwork', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/profile-sync-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"devDependencies": {
"@lavamoat/allow-scripts": "^3.0.4",
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/accounts-controller": "^21.0.0",
"@metamask/accounts-controller": "^21.0.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-internal-api": "^2.0.0",
"@metamask/providers": "^18.1.1",
Expand Down
15 changes: 15 additions & 0 deletions packages/token-search-discovery-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Initial work to introduce the TokenSearchDiscoveryController ([#5142](https://github.com/MetaMask/core/pull/5142/))
- This controller manages token search and discovery through the Portfolio API

[Unreleased]: https://github.com/MetaMask/core/
20 changes: 20 additions & 0 deletions packages/token-search-discovery-controller/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2025 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 changes: 15 additions & 0 deletions packages/token-search-discovery-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `@metamask/token-search-discovery-controller`

Manages token search and discovery through the Portfolio API.

## Installation

`yarn add @metamask/token-search-discovery-controller`

or

`npm install @metamask/token-search-discovery-controller`

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/token-search-discovery-controller/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
});
Loading

0 comments on commit 6700c42

Please sign in to comment.