Skip to content

Commit

Permalink
feat: add support for sepolia and arbitrum sepolia (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx authored Nov 22, 2023
1 parent be00852 commit ae8420e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ NEXT_PUBLIC_INFURA_KEY=

NEXT_PUBLIC_ETHEREUM_RPC_URL=
NEXT_PUBLIC_GOERLI_RPC_URL=
NEXT_PUBLIC_SEPOLIA_RPC_URL=

NEXT_PUBLIC_ARBITRUM_RPC_URL=
NEXT_PUBLIC_ARBITRUM_GOERLI_RPC_URL=
NEXT_PUBLIC_ARBITRUM_NOVA_RPC_URL=
NEXT_PUBLIC_ARBITRUM_SEPOLIA_RPC_URL=

NEXT_PUBLIC_LOCAL_ETHEREUM_RPC_URL=http://localhost:8545
NEXT_PUBLIC_LOCAL_ARBITRUM_RPC_URL=http://localhost:8547
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "Apache-2.0",
"private": true,
"dependencies": {
"@arbitrum/sdk": "^3.1.1",
"@arbitrum/sdk": "^3.1.12",
"@ethersproject/bignumber": "^5.1.1",
"@types/node": "^16.7.13",
"@types/react": "^18.0.26",
Expand Down
38 changes: 35 additions & 3 deletions src/components/WagmiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import {
arbitrumGoerli,
goerli,
localhost,
sepolia as sepoliaDefault,
} from 'wagmi/chains';
import { publicProvider } from 'wagmi/providers/public';
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc';
import { ReactNode } from 'react';
import { ChainId, rpcURLs } from '@/utils/network';

const ether = { name: 'Ether', symbol: 'ETH', decimals: 18 };

/**
* For e2e testing
*/
export const localL1Network: Chain = {
id: ChainId.Local,
name: 'EthLocal',
network: 'localhost',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
nativeCurrency: ether,
rpcUrls: {
default: rpcURLs[ChainId.Local],
public: rpcURLs[ChainId.Local],
Expand All @@ -33,7 +36,7 @@ export const localL2Network: Chain = {
id: ChainId.ArbitrumLocal,
name: 'ArbLocal',
network: 'arbitrum-local',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
nativeCurrency: ether,
rpcUrls: {
default: rpcURLs[ChainId.ArbitrumLocal],
public: rpcURLs[ChainId.ArbitrumLocal],
Expand All @@ -43,8 +46,37 @@ export const localL2Network: Chain = {
},
};

export const sepolia: Chain = {
...sepoliaDefault,
rpcUrls: {
...sepoliaDefault.rpcUrls,
// override the default public RPC with the Infura RPC
// public RPCs are getting rate limited
default: rpcURLs[ChainId.Sepolia],
},
};

export const arbitrumSepolia: Chain = {
id: ChainId.ArbitrumSepolia,
name: 'Arbitrum Sepolia',
network: 'arbitrum-sepolia',
nativeCurrency: ether,
rpcUrls: {
default: rpcURLs[ChainId.ArbitrumSepolia]!,
public: rpcURLs[ChainId.ArbitrumSepolia]!,
},
};

const { provider, webSocketProvider } = configureChains(
[mainnet, goerli, arbitrum, arbitrumGoerli, localhost],
[
mainnet,
goerli,
sepolia,
arbitrum,
arbitrumGoerli,
arbitrumSepolia,
localhost,
],
[
publicProvider(),
jsonRpcProvider({
Expand Down
22 changes: 7 additions & 15 deletions src/utils/getL1ToL2MessagesAndDepositMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@/types';
import { getL2Network, L1Network, L1TransactionReceipt } from '@arbitrum/sdk';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { ChainId, rpcURLs } from './network';

export const getL1ToL2MessagesAndDepositMessages = async (
l1TxnReceipt: L1TransactionReceipt,
Expand All @@ -24,22 +25,13 @@ export const getL1ToL2MessagesAndDepositMessages = async (
return;
}

let l2RpcURL;
switch (l2ChainID) {
case 42161:
l2RpcURL = 'https://arb1.arbitrum.io/rpc';
break;
case 42170:
l2RpcURL = 'https://nova.arbitrum.io/rpc';
break;
case 421613:
l2RpcURL = 'https://goerli-rollup.arbitrum.io/rpc';
break;
default:
throw new Error(
'Unknown L2 chain id. This chain is not supported by dashboard',
);
const l2RpcURL = rpcURLs[l2ChainID as ChainId];
if (!l2RpcURL) {
throw new Error(
'Unknown L2 chain id. This chain is not supported by dashboard',
);
}

const l2Provider = new StaticJsonRpcProvider(l2RpcURL);
const isClassic = await l1TxnReceipt.isClassic(l2Provider);

Expand Down
6 changes: 1 addition & 5 deletions src/utils/getProviderFromChainId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { ChainId, rpcURLs } from './network';
import { StaticJsonRpcProvider } from '@ethersproject/providers';

export const getProviderFromChainId = (chainID: number) => {
const l2RpcURL = {
[ChainId.ArbitrumOne]: rpcURLs[ChainId.ArbitrumOne],
[ChainId.ArbitrumGoerli]: rpcURLs[ChainId.ArbitrumGoerli],
}[chainID];

const l2RpcURL = rpcURLs[chainID as ChainId];
if (!l2RpcURL) {
throw new Error(
'Unknown L2 chain id. This chain is not supported by this tool',
Expand Down
22 changes: 19 additions & 3 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ if (typeof INFURA_KEY === 'undefined') {
throw new Error('process.env.NEXT_PUBLIC_INFURA_KEY not provided');
}

// L1
const MAINNET_INFURA_RPC_URL = `https://mainnet.infura.io/v3/${INFURA_KEY}`;
const GOERLI_INFURA_RPC_URL = `https://goerli.infura.io/v3/${INFURA_KEY}`;
const SEPOLIA_INFURA_RPC_URL = `https://sepolia.infura.io/v3/${INFURA_KEY}`;
// L2
const ARBITRUM_INFURA_RPC_URL = `https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`;
const ARBITRUM_GOERLI_INFURA_RPC_URL = `https://arbitrum-goerli.infura.io/v3/${INFURA_KEY}`;
const ARBITRUM_SEPOLIA_INFURA_RPC_URL = `https://arbitrum-sepolia.infura.io/v3/${INFURA_KEY}`;
const LOCAL_GETH_RPC_URL = `http://localhost:8545`;

export enum ChainId {
// L1
Mainnet = 1,
// L1 Testnets
Goerli = 5,
Sepolia = 11155111,
Local = 1337,
// L2
ArbitrumOne = 42161,
ArbitrumNova = 42170,
// L2 Testnets
ArbitrumGoerli = 421613,
ArbitrumLocal = 412346,
ArbitrumSepolia = 421614,
}

const isE2e = process.env.NODE_ENV === 'test';
Expand All @@ -40,19 +46,27 @@ export const rpcURLs: RpcMap = {
env: process.env.NEXT_PUBLIC_GOERLI_RPC_URL,
fallback: GOERLI_INFURA_RPC_URL,
}),
[ChainId.Sepolia]: loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_SEPOLIA_RPC_URL,
fallback: SEPOLIA_INFURA_RPC_URL,
}),
// L2
[ChainId.ArbitrumOne]: loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_ARBITRUM_RPC_URL,
fallback: ARBITRUM_INFURA_RPC_URL,
}),
[ChainId.ArbitrumNova]: loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_ARBITRUM_NOVA_RPC_URL,
fallback: 'https://nova.arbitrum.io/rpc',
}),
// L2 Testnets
[ChainId.ArbitrumGoerli]: loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_ARBITRUM_GOERLI_RPC_URL,
fallback: ARBITRUM_GOERLI_INFURA_RPC_URL,
}),
[ChainId.ArbitrumNova]: loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_ARBITRUM_NOVA_RPC_URL,
fallback: 'https://nova.arbitrum.io/rpc',
[ChainId.ArbitrumSepolia]: loadEnvironmentVariableWithFallback({
env: process.env.NEXT_PUBLIC_ARBITRUM_SEPOLIA_RPC_URL,
fallback: ARBITRUM_SEPOLIA_INFURA_RPC_URL,
}),
// E2E RPCs
[ChainId.Local]: loadEnvironmentVariableWithFallback({
Expand All @@ -68,13 +82,15 @@ export const rpcURLs: RpcMap = {
export const supportedL1Networks: Partial<RpcMap> = {
[ChainId.Mainnet]: rpcURLs[ChainId.Mainnet],
[ChainId.Goerli]: rpcURLs[ChainId.Goerli],
[ChainId.Sepolia]: rpcURLs[ChainId.Sepolia],
...(isE2e ? { [ChainId.Local]: rpcURLs[ChainId.Local] } : {}),
};

export const supportedL2Networks: Partial<RpcMap> = {
[ChainId.ArbitrumOne]: rpcURLs[ChainId.ArbitrumOne],
[ChainId.ArbitrumNova]: rpcURLs[ChainId.ArbitrumNova],
[ChainId.ArbitrumGoerli]: rpcURLs[ChainId.ArbitrumGoerli],
[ChainId.ArbitrumSepolia]: rpcURLs[ChainId.ArbitrumSepolia],
...(isE2e ? { [ChainId.ArbitrumLocal]: rpcURLs[ChainId.ArbitrumLocal] } : {}),
};

Expand Down
16 changes: 12 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
"@jridgewell/gen-mapping" "^0.3.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@arbitrum/sdk@^3.1.1":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@arbitrum/sdk/-/sdk-3.1.3.tgz#75236043717a450b569faaa087687c51d525b0c3"
integrity sha512-Dn1or7/Guc3dItuiiWaoYQ37aCDwiWTZGPIrg4yBJW27BgiDGbo0mjPDAhKTh4p5NDOWyE8bZ0vZai86COZIUA==
"@arbitrum/sdk@^3.1.12":
version "3.1.13"
resolved "https://registry.yarnpkg.com/@arbitrum/sdk/-/sdk-3.1.13.tgz#a0d3d9a7b387f42547c63f6f066d8a6c4dd945cc"
integrity sha512-oE/j8ThWWEdFfV0helmR8lD0T67/CY1zMCt6RVslaCLrytFdbg3QsrHs/sQE3yiCXgisQlsx3qomCgh8PfBo8Q==
dependencies:
"@ethersproject/address" "^5.0.8"
"@ethersproject/bignumber" "^5.1.1"
"@ethersproject/bytes" "^5.0.8"
async-mutex "^0.4.0"
ethers "^5.1.0"

"@babel/code-frame@^7.10.4", "@babel/code-frame@^7.21.4":
Expand Down Expand Up @@ -2200,6 +2201,13 @@ async-mutex@^0.2.6:
dependencies:
tslib "^2.0.0"

async-mutex@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.4.0.tgz#ae8048cd4d04ace94347507504b3cf15e631c25f"
integrity sha512-eJFZ1YhRR8UN8eBLoNzcDPcy/jqjsg6I1AP+KvWQX80BqOSW1oJPJXDylPUEeMr2ZQvHgnQ//Lp6f3RQ1zI7HA==
dependencies:
tslib "^2.4.0"

async@^2.6.1:
version "2.6.4"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221"
Expand Down

1 comment on commit ae8420e

@vercel
Copy link

@vercel vercel bot commented on ae8420e Nov 22, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.