From 9199d0da3a4b0e91391c25baf60a0db13a9d967d Mon Sep 17 00:00:00 2001 From: spsjvc Date: Wed, 20 Dec 2023 18:29:21 +0100 Subject: [PATCH] feat: add support for nitro-testnode (#21) --- src/chains.ts | 43 +++++++++++++++++++++++++++++-- src/createRollupGetMaxDataSize.ts | 4 +-- src/package.json | 7 +++++ src/prepareNodeConfig.ts | 9 ++++++- wagmi.config.ts | 24 ++++++++++++++++- 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/chains.ts b/src/chains.ts index 91b5bd23..ae120967 100644 --- a/src/chains.ts +++ b/src/chains.ts @@ -1,4 +1,43 @@ +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 }; diff --git a/src/createRollupGetMaxDataSize.ts b/src/createRollupGetMaxDataSize.ts index b590adad..db7368e0 100644 --- a/src/createRollupGetMaxDataSize.ts +++ b/src/createRollupGetMaxDataSize.ts @@ -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); } diff --git a/src/package.json b/src/package.json index 637d3c72..5d7a5838 100644 --- a/src/package.json +++ b/src/package.json @@ -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" @@ -22,6 +26,9 @@ }, "typesVersions": { "*": { + "chains": [ + "./dist/chains.d.ts" + ], "contracts": [ "./dist/contracts.d.ts" ], diff --git a/src/prepareNodeConfig.ts b/src/prepareNodeConfig.ts index ace51245..9089e375 100644 --- a/src/prepareNodeConfig.ts +++ b/src/prepareNodeConfig.ts @@ -6,7 +6,12 @@ import { import { ChainConfig } from './types/ChainConfig'; import { CoreContracts } from './types/CoreContracts'; import { ParentChainId, validParentChainId } from './types/ParentChain'; -import { sepolia, arbitrumSepolia } from './chains'; +import { + sepolia, + arbitrumSepolia, + nitroTestnodeL1, + nitroTestnodeL2, +} from './chains'; function sanitizePrivateKey(privateKey: string) { return privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey; @@ -26,9 +31,11 @@ function parentChainIsArbitrum(parentChainId: ParentChainId): boolean { // doing switch here to make sure it's exhaustive when checking against `ParentChainId` switch (parentChainId) { case sepolia.id: + case nitroTestnodeL1.id: return false; case arbitrumSepolia.id: + case nitroTestnodeL2.id: return true; } } diff --git a/wagmi.config.ts b/wagmi.config.ts index da2bd556..c92ed9e0 100644 --- a/wagmi.config.ts +++ b/wagmi.config.ts @@ -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(); @@ -17,8 +22,12 @@ function sleep(ms: number = 3_000) { } const blockExplorerApiUrls: Record = { + // 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 we skip abi fetch + [nitroTestnodeL1.id]: '', + [nitroTestnodeL2.id]: '', }; export async function fetchAbi(chainId: ParentChainId, address: `0x${string}`) { @@ -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 "use-tokenbridge-creator" branch) + [nitroTestnodeL1.id]: '0x596eabe0291d4cdafac7ef53d16c92bf6922b5e0', + [nitroTestnodeL2.id]: '0x3BaF9f08bAD68869eEdEa90F2Cc546Bd80F1A651', }, }, { name: 'TokenBridgeCreator', version: '1.1.2', address: { + // testnet [sepolia.id]: '0x7612718D3143C791B2Ff5c01a9a7D02CEf00AE9c', [arbitrumSepolia.id]: '0xb462C69f8f638d2954c9618B03765FC1770190cF', + // local nitro-testnode (on "use-tokenbridge-creator" branch) + [nitroTestnodeL1.id]: '0x4a2ba922052ba54e29c5417bc979daaf7d5fe4f4', + [nitroTestnodeL2.id]: '0x38f35af53bf913c439eab06a367e09d6eb253492', }, }, { @@ -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)