From 6c05f77acc27ca1d181b509d2c97904754cd17e9 Mon Sep 17 00:00:00 2001 From: VGau Date: Wed, 28 Feb 2024 18:14:36 +0100 Subject: [PATCH 1/2] feat: add linea sepolia network support in controller utils package and in network/name/preferences/transaction controllers packages --- packages/controller-utils/src/constants.ts | 9 ++ packages/controller-utils/src/types.test.ts | 1 + packages/controller-utils/src/types.ts | 4 + packages/name-controller/src/constants.ts | 5 + packages/network-controller/package.json | 2 +- .../tests/NetworkController.test.ts | 114 +++++++++++++++++- .../src/PreferencesController.ts | 1 + .../preferences-controller/src/constants.ts | 1 + .../transaction-controller/src/constants.ts | 5 + .../src/gas-flows/LineaGasFeeFlow.test.ts | 3 +- .../src/gas-flows/LineaGasFeeFlow.ts | 1 + yarn.lock | 28 +++-- 12 files changed, 162 insertions(+), 12 deletions(-) diff --git a/packages/controller-utils/src/constants.ts b/packages/controller-utils/src/constants.ts index aaee292fc1..a019afb80b 100644 --- a/packages/controller-utils/src/constants.ts +++ b/packages/controller-utils/src/constants.ts @@ -47,6 +47,7 @@ export const TESTNET_TICKER_SYMBOLS = { GOERLI: 'GoerliETH', SEPOLIA: 'SepoliaETH', LINEA_GOERLI: 'LineaETH', + LINEA_SEPOLIA: 'LineaETH', }; /** @@ -81,6 +82,13 @@ export const BUILT_IN_NETWORKS = { blockExplorerUrl: 'https://goerli.lineascan.build', }, }, + [NetworkType['linea-sepolia']]: { + chainId: ChainId['linea-sepolia'], + ticker: NetworksTicker['linea-sepolia'], + rpcPrefs: { + blockExplorerUrl: 'https://sepolia.lineascan.build', + }, + }, [NetworkType['linea-mainnet']]: { chainId: ChainId['linea-mainnet'], ticker: NetworksTicker['linea-mainnet'], @@ -137,6 +145,7 @@ export const CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP: Record< [ChainId.sepolia]: BuiltInNetworkName.Sepolia, [ChainId.mainnet]: BuiltInNetworkName.Mainnet, [ChainId['linea-goerli']]: BuiltInNetworkName.LineaGoerli, + [ChainId['linea-sepolia']]: BuiltInNetworkName.LineaSepolia, [ChainId['linea-mainnet']]: BuiltInNetworkName.LineaMainnet, [ChainId.aurora]: BuiltInNetworkName.Aurora, }; diff --git a/packages/controller-utils/src/types.test.ts b/packages/controller-utils/src/types.test.ts index ddac15c499..b987180153 100644 --- a/packages/controller-utils/src/types.test.ts +++ b/packages/controller-utils/src/types.test.ts @@ -10,6 +10,7 @@ describe('types', () => { expect(isNetworkType(NetworkType.goerli)).toBe(true); expect(isNetworkType(NetworkType.sepolia)).toBe(true); expect(isNetworkType(NetworkType['linea-goerli'])).toBe(true); + expect(isNetworkType(NetworkType['linea-sepolia'])).toBe(true); expect(isNetworkType(NetworkType['linea-mainnet'])).toBe(true); expect(isNetworkType(NetworkType.rpc)).toBe(true); }); diff --git a/packages/controller-utils/src/types.ts b/packages/controller-utils/src/types.ts index 248d7623b9..dc6d4f7a24 100644 --- a/packages/controller-utils/src/types.ts +++ b/packages/controller-utils/src/types.ts @@ -6,6 +6,7 @@ export const InfuraNetworkType = { goerli: 'goerli', sepolia: 'sepolia', 'linea-goerli': 'linea-goerli', + 'linea-sepolia': 'linea-sepolia', 'linea-mainnet': 'linea-mainnet', } as const; @@ -58,6 +59,7 @@ export enum BuiltInNetworkName { Goerli = 'goerli', Sepolia = 'sepolia', LineaGoerli = 'linea-goerli', + LineaSepolia = 'linea-sepolia', LineaMainnet = 'linea-mainnet', Aurora = 'aurora', } @@ -73,6 +75,7 @@ export const ChainId = { [BuiltInNetworkName.Sepolia]: '0xaa36a7', // toHex(11155111) [BuiltInNetworkName.Aurora]: '0x4e454152', // toHex(1313161554) [BuiltInNetworkName.LineaGoerli]: '0xe704', // toHex(59140) + [BuiltInNetworkName.LineaSepolia]: '0xe705', // toHex(59141) [BuiltInNetworkName.LineaMainnet]: '0xe708', // toHex(59144) } as const; export type ChainId = (typeof ChainId)[keyof typeof ChainId]; @@ -82,6 +85,7 @@ export enum NetworksTicker { goerli = 'GoerliETH', sepolia = 'SepoliaETH', 'linea-goerli' = 'LineaETH', + 'linea-sepolia' = 'LineaETH', 'linea-mainnet' = 'ETH', rpc = '', } diff --git a/packages/name-controller/src/constants.ts b/packages/name-controller/src/constants.ts index 6a5b4767f5..041b1e21d6 100644 --- a/packages/name-controller/src/constants.ts +++ b/packages/name-controller/src/constants.ts @@ -15,6 +15,7 @@ export const CHAIN_IDS = { FANTOM_TESTNET: '0xfa2', SEPOLIA: '0xaa36a7', LINEA_GOERLI: '0xe704', + LINEA_SEPOLIA: '0xe705', LINEA_MAINNET: '0xe708', MOONBEAM: '0x504', MOONBEAM_TESTNET: '0x507', @@ -42,6 +43,10 @@ export const ETHERSCAN_SUPPORTED_NETWORKS = { domain: 'lineascan.build', subdomain: 'goerli', }, + [CHAIN_IDS.LINEA_SEPOLIA]: { + domain: 'lineascan.build', + subdomain: 'sepolia', + }, [CHAIN_IDS.LINEA_MAINNET]: { domain: 'lineascan.build', subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX, diff --git a/packages/network-controller/package.json b/packages/network-controller/package.json index d11899ef96..034c0dac30 100644 --- a/packages/network-controller/package.json +++ b/packages/network-controller/package.json @@ -33,7 +33,7 @@ "dependencies": { "@metamask/base-controller": "^4.1.1", "@metamask/controller-utils": "^8.0.3", - "@metamask/eth-json-rpc-infura": "^9.0.0", + "@metamask/eth-json-rpc-infura": "^9.1.0", "@metamask/eth-json-rpc-middleware": "^12.1.0", "@metamask/eth-json-rpc-provider": "^2.3.2", "@metamask/eth-query": "^4.0.0", diff --git a/packages/network-controller/tests/NetworkController.test.ts b/packages/network-controller/tests/NetworkController.test.ts index d1aeaa970e..c2adcdb7f7 100644 --- a/packages/network-controller/tests/NetworkController.test.ts +++ b/packages/network-controller/tests/NetworkController.test.ts @@ -94,6 +94,12 @@ const INFURA_NETWORKS = [ ticker: 'LineaETH', blockExplorerUrl: 'https://goerli.lineascan.build', }, + { + networkType: NetworkType['linea-sepolia'], + chainId: toHex(59141), + ticker: 'LineaETH', + blockExplorerUrl: 'https://sepolia.lineascan.build', + }, { networkType: NetworkType['linea-mainnet'], chainId: toHex(59144), @@ -1318,6 +1324,18 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[NetworkType['linea-sepolia']].chainId, + ticker: + BUILT_IN_NETWORKS[NetworkType['linea-sepolia']].ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -1437,6 +1455,18 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[NetworkType['linea-sepolia']].chainId, + ticker: + BUILT_IN_NETWORKS[NetworkType['linea-sepolia']].ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -1539,6 +1569,20 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .chainId, + ticker: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -1667,6 +1711,20 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .chainId, + ticker: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -1788,6 +1846,20 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .chainId, + ticker: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -1909,6 +1981,20 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .chainId, + ticker: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -2031,6 +2117,20 @@ describe('NetworkController', () => { network: InfuraNetworkType['linea-mainnet'], }, ], + [ + 'linea-sepolia', + { + type: NetworkClientType.Infura, + infuraProjectId: 'some-infura-project-id', + chainId: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .chainId, + ticker: + BUILT_IN_NETWORKS[InfuraNetworkType['linea-sepolia']] + .ticker, + network: InfuraNetworkType['linea-sepolia'], + }, + ], [ 'mainnet', { @@ -3768,6 +3868,14 @@ describe('NetworkController', () => { blockExplorerUrl: 'https://goerli.lineascan.build', }, }, + [InfuraNetworkType['linea-sepolia']]: { + rpcUrl: 'https://linea-sepolia.infura.io/v3/some-infura-project-id', + chainId: '0xe705' as const, + ticker: 'LineaETH', + rpcPrefs: { + blockExplorerUrl: 'https://sepolia.lineascan.build', + }, + }, [InfuraNetworkType['linea-mainnet']]: { rpcUrl: 'https://linea-mainnet.infura.io/v3/some-infura-project-id', chainId: '0xe708' as const, @@ -3974,7 +4082,7 @@ describe('NetworkController', () => { ); const networkClients = controller.getNetworkClientRegistry(); - expect(Object.keys(networkClients)).toHaveLength(6); + expect(Object.keys(networkClients)).toHaveLength(7); expect(networkClients).toMatchObject({ 'AAAA-AAAA-AAAA-AAAA': expect.objectContaining({ configuration: { @@ -4554,7 +4662,7 @@ describe('NetworkController', () => { const networkClients = controller.getNetworkClientRegistry(); expect(networkClientToDestroy.destroy).toHaveBeenCalled(); - expect(Object.keys(networkClients)).toHaveLength(6); + expect(Object.keys(networkClients)).toHaveLength(7); expect(networkClients).not.toMatchObject({ [oldRpcUrl]: expect.objectContaining({ configuration: { @@ -4610,7 +4718,7 @@ describe('NetworkController', () => { ); const networkClients = controller.getNetworkClientRegistry(); - expect(Object.keys(networkClients)).toHaveLength(6); + expect(Object.keys(networkClients)).toHaveLength(7); expect(networkClients).toMatchObject({ 'AAAA-AAAA-AAAA-AAAA': expect.objectContaining({ configuration: { diff --git a/packages/preferences-controller/src/PreferencesController.ts b/packages/preferences-controller/src/PreferencesController.ts index b7e53e5d69..aaf1057e0e 100644 --- a/packages/preferences-controller/src/PreferencesController.ts +++ b/packages/preferences-controller/src/PreferencesController.ts @@ -187,6 +187,7 @@ export function getDefaultPreferencesState() { [ETHERSCAN_SUPPORTED_CHAIN_IDS.FANTOM_TESTNET]: true, [ETHERSCAN_SUPPORTED_CHAIN_IDS.SEPOLIA]: true, [ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_GOERLI]: true, + [ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_SEPOLIA]: true, [ETHERSCAN_SUPPORTED_CHAIN_IDS.LINEA_MAINNET]: true, [ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM]: true, [ETHERSCAN_SUPPORTED_CHAIN_IDS.MOONBEAM_TESTNET]: true, diff --git a/packages/preferences-controller/src/constants.ts b/packages/preferences-controller/src/constants.ts index 2fd321a5a9..05f6f38033 100644 --- a/packages/preferences-controller/src/constants.ts +++ b/packages/preferences-controller/src/constants.ts @@ -13,6 +13,7 @@ export const ETHERSCAN_SUPPORTED_CHAIN_IDS = { FANTOM_TESTNET: '0xfa2', SEPOLIA: '0xaa36a7', LINEA_GOERLI: '0xe704', + LINEA_SEPOLIA: '0xe705', LINEA_MAINNET: '0xe708', MOONBEAM: '0x504', MOONBEAM_TESTNET: '0x507', diff --git a/packages/transaction-controller/src/constants.ts b/packages/transaction-controller/src/constants.ts index d35ff04335..6523c8bb36 100644 --- a/packages/transaction-controller/src/constants.ts +++ b/packages/transaction-controller/src/constants.ts @@ -13,6 +13,7 @@ export const CHAIN_IDS = { FANTOM_TESTNET: '0xfa2', SEPOLIA: '0xaa36a7', LINEA_GOERLI: '0xe704', + LINEA_SEPOLIA: '0xe705', LINEA_MAINNET: '0xe708', MOONBEAM: '0x504', MOONBEAM_TESTNET: '0x507', @@ -42,6 +43,10 @@ export const ETHERSCAN_SUPPORTED_NETWORKS = { domain: 'lineascan.build', subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-goerli`, }, + [CHAIN_IDS.LINEA_SEPOLIA]: { + domain: 'lineascan.build', + subdomain: `${DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX}-sepolia`, + }, [CHAIN_IDS.LINEA_MAINNET]: { domain: 'lineascan.build', subdomain: DEFAULT_ETHERSCAN_SUBDOMAIN_PREFIX, diff --git a/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts b/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts index 01281c9721..b7a536bbd7 100644 --- a/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts +++ b/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.test.ts @@ -72,7 +72,8 @@ describe('LineaGasFeeFlow', () => { describe('matchesTransaction', () => { it.each([ ['linea mainnet', CHAIN_IDS.LINEA_MAINNET], - ['linea testnet', CHAIN_IDS.LINEA_GOERLI], + ['linea goerli testnet', CHAIN_IDS.LINEA_GOERLI], + ['linea sepolia testnet', CHAIN_IDS.LINEA_SEPOLIA], ])('returns true if chain ID is %s', (_title, chainId) => { const flow = new LineaGasFeeFlow(); diff --git a/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.ts b/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.ts index a6ebeed574..c0ed12fc60 100644 --- a/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.ts +++ b/packages/transaction-controller/src/gas-flows/LineaGasFeeFlow.ts @@ -28,6 +28,7 @@ const log = createModuleLogger(projectLogger, 'linea-gas-fee-flow'); const LINEA_CHAIN_IDS: Hex[] = [ ChainId['linea-mainnet'], ChainId['linea-goerli'], + ChainId['linea-sepolia'], ]; const BASE_FEE_MULTIPLIERS = { diff --git a/yarn.lock b/yarn.lock index a6d71e8b27..c0ffac974c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1913,16 +1913,16 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-json-rpc-infura@npm:^9.0.0": - version: 9.0.0 - resolution: "@metamask/eth-json-rpc-infura@npm:9.0.0" +"@metamask/eth-json-rpc-infura@npm:^9.1.0": + version: 9.1.0 + resolution: "@metamask/eth-json-rpc-infura@npm:9.1.0" dependencies: "@metamask/eth-json-rpc-provider": ^2.1.0 "@metamask/json-rpc-engine": ^7.1.1 "@metamask/rpc-errors": ^6.0.0 "@metamask/utils": ^8.1.0 - node-fetch: ^2.6.7 - checksum: 3dd6783dd54a72fc479496212524150e3e3f6869a135a02709d3ef9c2d7a2e2b99690eef91776c269da3c0d79709daed0c8693549cb8dd999e5b3d96e0b106c0 + node-fetch: ^2.7.0 + checksum: 58f2a6b6ce9c545c9210b2ab3f8c0946cc82ed02c82a096406d8c7146c89c1eba1a13e472048a6e252906dd5eb336e63238d9a5446407c1d46b1d6a40e2a64f4 languageName: node linkType: hard @@ -2341,7 +2341,7 @@ __metadata: "@metamask/auto-changelog": ^3.4.4 "@metamask/base-controller": ^4.1.1 "@metamask/controller-utils": ^8.0.3 - "@metamask/eth-json-rpc-infura": ^9.0.0 + "@metamask/eth-json-rpc-infura": ^9.1.0 "@metamask/eth-json-rpc-middleware": ^12.1.0 "@metamask/eth-json-rpc-provider": ^2.3.2 "@metamask/eth-query": ^4.0.0 @@ -8917,7 +8917,7 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:^2.6.1, node-fetch@npm:^2.6.7": +"node-fetch@npm:^2.6.1": version: 2.6.12 resolution: "node-fetch@npm:2.6.12" dependencies: @@ -8931,6 +8931,20 @@ __metadata: languageName: node linkType: hard +"node-fetch@npm:^2.7.0": + version: 2.7.0 + resolution: "node-fetch@npm:2.7.0" + dependencies: + whatwg-url: ^5.0.0 + peerDependencies: + encoding: ^0.1.0 + peerDependenciesMeta: + encoding: + optional: true + checksum: d76d2f5edb451a3f05b15115ec89fc6be39de37c6089f1b6368df03b91e1633fd379a7e01b7ab05089a25034b2023d959b47e59759cb38d88341b2459e89d6e5 + languageName: node + linkType: hard + "node-gyp-build@npm:^4.2.0": version: 4.6.0 resolution: "node-gyp-build@npm:4.6.0" From 58559417482ac591bc716359badd3099223a15a2 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Fri, 8 Mar 2024 10:14:10 -0700 Subject: [PATCH 2/2] yarn dedupe --- yarn.lock | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/yarn.lock b/yarn.lock index aca2eef9d9..2220dc6d1c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9350,21 +9350,7 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:^2.6.1": - version: 2.6.12 - resolution: "node-fetch@npm:2.6.12" - dependencies: - whatwg-url: ^5.0.0 - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - checksum: 3bc1655203d47ee8e313c0d96664b9673a3d4dd8002740318e9d27d14ef306693a4b2ef8d6525775056fd912a19e23f3ac0d7111ad8925877b7567b29a625592 - languageName: node - linkType: hard - -"node-fetch@npm:^2.7.0": +"node-fetch@npm:^2.6.1, node-fetch@npm:^2.7.0": version: 2.7.0 resolution: "node-fetch@npm:2.7.0" dependencies: