Skip to content

Commit

Permalink
feat: add linea sepolia network support (#3995)
Browse files Browse the repository at this point in the history
A new Linea Sepolia network will be added to MetaMask soon. This PR adds
the Linea Sepolia network to several packages:

- controller-utils
- network-controller
- name-controller
- preferences-controller
- transaction-controller

---

Co-authored-by: Elliot Winkler <[email protected]>
  • Loading branch information
VGau and mcmire authored Mar 8, 2024
1 parent caee13a commit 4e03239
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 15 deletions.
9 changes: 9 additions & 0 deletions packages/controller-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const TESTNET_TICKER_SYMBOLS = {
GOERLI: 'GoerliETH',
SEPOLIA: 'SepoliaETH',
LINEA_GOERLI: 'LineaETH',
LINEA_SEPOLIA: 'LineaETH',
};

/**
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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,
};
1 change: 1 addition & 0 deletions packages/controller-utils/src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/controller-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,6 +57,7 @@ export enum BuiltInNetworkName {
Goerli = 'goerli',
Sepolia = 'sepolia',
LineaGoerli = 'linea-goerli',
LineaSepolia = 'linea-sepolia',
LineaMainnet = 'linea-mainnet',
Aurora = 'aurora',
}
Expand All @@ -71,6 +73,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];
Expand All @@ -80,6 +83,7 @@ export enum NetworksTicker {
goerli = 'GoerliETH',
sepolia = 'SepoliaETH',
'linea-goerli' = 'LineaETH',
'linea-sepolia' = 'LineaETH',
'linea-mainnet' = 'ETH',
rpc = '',
}
5 changes: 5 additions & 0 deletions packages/name-controller/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/network-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@metamask/base-controller": "^4.1.1",
"@metamask/controller-utils": "^8.0.4",
"@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",
Expand Down
114 changes: 111 additions & 3 deletions packages/network-controller/tests/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/preferences-controller/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions packages/transaction-controller/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading

0 comments on commit 4e03239

Please sign in to comment.