Skip to content

Commit

Permalink
feat: add support for nitro-testnode
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Dec 20, 2023
1 parent d3eef21 commit f670d69
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
38 changes: 36 additions & 2 deletions src/chains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
import { defineChain } from 'viem';
import { sepolia, arbitrumSepolia } from 'viem/chains';

export const chains = [sepolia, arbitrumSepolia];
export { sepolia, arbitrumSepolia };
const nitroTestnodeL1 = defineChain({
id: 1_337,
network: 'Nitro Testnode L1',
name: 'nitro-testnode-l1',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: ['http://127.0.0.1:8545'],
},
public: {
http: ['http://127.0.0.1:8545'],
},
},

testnet: true,
});

const nitroTestnodeL2 = defineChain({
id: 412_346,
network: 'Nitro Testnode L2',
name: 'nitro-testnode-l2',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: ['http://127.0.0.1:8547'],
},
public: {
http: ['http://127.0.0.1:8547'],
},
},
testnet: true,
});

export const chains = [sepolia, arbitrumSepolia, nitroTestnodeL1, nitroTestnodeL2] as const;
export { sepolia, arbitrumSepolia, nitroTestnodeL1, nitroTestnodeL2 };
4 changes: 2 additions & 2 deletions src/createRollupGetMaxDataSize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sepolia } from './chains';
import { sepolia, nitroTestnodeL1 } from './chains';
import { ParentChainId } from './types/ParentChain';

export function createRollupGetMaxDataSize(parentChainId: ParentChainId) {
// L2
if (parentChainId === sepolia.id) {
if (parentChainId === sepolia.id || parentChainId === nitroTestnodeL1.id) {
return BigInt(117_964);
}

Expand Down
7 changes: 7 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./chains": {
"types": "./dist/chains.d.ts",
"default": "./dist/chains.js"
},
"./contracts": {
"types": "./dist/contracts.d.ts",
"default": "./dist/contracts.js"
Expand All @@ -22,6 +26,9 @@
},
"typesVersions": {
"*": {
"chains": [
"./dist/chains.d.ts"
],
"contracts": [
"./dist/contracts.d.ts"
],
Expand Down
24 changes: 23 additions & 1 deletion wagmi.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { erc, etherscan } from '@wagmi/cli/plugins';
import dotenv from 'dotenv';

import { ParentChainId } from './src';
import { sepolia, arbitrumSepolia } from './src/chains';
import {
sepolia,
arbitrumSepolia,
nitroTestnodeL1,
nitroTestnodeL2,
} from './src/chains';

dotenv.config();

Expand All @@ -17,8 +22,12 @@ function sleep(ms: number = 3_000) {
}

const blockExplorerApiUrls: Record<ParentChainId, string> = {
// testnet
[sepolia.id]: 'https://api-sepolia.etherscan.io/api',
[arbitrumSepolia.id]: 'https://api-sepolia.arbiscan.io/api',
// local nitro-testnode / fine to omit these as skip abi fetch
[nitroTestnodeL1.id]: '',
[nitroTestnodeL2.id]: '',
};

export async function fetchAbi(chainId: ParentChainId, address: `0x${string}`) {
Expand All @@ -40,16 +49,24 @@ const contracts: ContractConfig[] = [
name: 'RollupCreator',
version: '1.1.0',
address: {
// testnet
[sepolia.id]: '0xfbd0b034e6305788007f6e0123cc5eae701a5751',
[arbitrumSepolia.id]: '0x06E341073b2749e0Bb9912461351f716DeCDa9b0',
// local nitro-testnode (on master)
[nitroTestnodeL1.id]: '0x596eabe0291d4cdafac7ef53d16c92bf6922b5e0',
[nitroTestnodeL2.id]: '0x3BaF9f08bAD68869eEdEa90F2Cc546Bd80F1A651',
},
},
{
name: 'TokenBridgeCreator',
version: '1.1.2',
address: {
// testnet
[sepolia.id]: '0x7612718D3143C791B2Ff5c01a9a7D02CEf00AE9c',
[arbitrumSepolia.id]: '0xb462C69f8f638d2954c9618B03765FC1770190cF',
// local nitro-testnode (on master) doesn't have these yet
[nitroTestnodeL1.id]: '0x0000000000000000000000000000000000000000',
[nitroTestnodeL2.id]: '0x0000000000000000000000000000000000000000',
},
},
{
Expand All @@ -75,6 +92,11 @@ export async function assertContractAbisMatch(contract: ContractConfig) {

const abis = await Promise.all(
Object.entries(contract.address)
// don't fetch abis for testnode
.filter(([chainIdString]) => {
const chainId = Number(chainIdString);
return chainId !== nitroTestnodeL1.id && chainId !== nitroTestnodeL2.id;
})
// fetch abis for all chains
.map(([chainId, address]) =>
fetchAbi(Number(chainId) as ParentChainId, address)
Expand Down

0 comments on commit f670d69

Please sign in to comment.