From 5a06672db92da276f33487b7fc5ad36ab93bce5c Mon Sep 17 00:00:00 2001 From: Doug <4741454+douglance@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:42:30 -0400 Subject: [PATCH] adds `getProvider` --- .../scripts/src/addOrbitChain/provider.ts | 37 +++++++++++++++++++ packages/scripts/src/addOrbitChain/schemas.ts | 3 +- .../scripts/src/addOrbitChain/transforms.ts | 36 +----------------- 3 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 packages/scripts/src/addOrbitChain/provider.ts diff --git a/packages/scripts/src/addOrbitChain/provider.ts b/packages/scripts/src/addOrbitChain/provider.ts new file mode 100644 index 0000000000..cb958a2748 --- /dev/null +++ b/packages/scripts/src/addOrbitChain/provider.ts @@ -0,0 +1,37 @@ +import { StaticJsonRpcProvider } from "@ethersproject/providers"; +import { ConnectionInfo } from "ethers/lib/utils"; + +class LoggingProvider extends StaticJsonRpcProvider { + perform(method: string, parameters: any): Promise { + console.log(">>>", method, parameters); + return super.perform(method, parameters).then((result) => { + console.log("<<<", method, parameters, result); + return result; + }); + } +} +export const getProvider = (chainInfo: { + rpcUrl: string; + name: string; + chainId: number; +}) => { + const connection: ConnectionInfo = { + url: chainInfo.rpcUrl, + timeout: 30000, + allowGzip: true, + skipFetchSetup: true, + throttleLimit: 3, + throttleSlotInterval: 1000, + headers: { + Accept: "*/*", + "Accept-Encoding": "gzip, deflate, br", + }, + }; + + const provider = new LoggingProvider(connection, { + name: chainInfo.name, + chainId: chainInfo.chainId, + }); + + return provider; +}; diff --git a/packages/scripts/src/addOrbitChain/schemas.ts b/packages/scripts/src/addOrbitChain/schemas.ts index ee11c4fc1f..9e75a3e69c 100644 --- a/packages/scripts/src/addOrbitChain/schemas.ts +++ b/packages/scripts/src/addOrbitChain/schemas.ts @@ -3,6 +3,7 @@ import { constants, ethers } from "ethers"; import { getOctokit } from "@actions/github"; import path from "path"; import * as dotenv from "dotenv"; +import { getProvider } from "./provider"; // Load .env from the UI project directory dotenv.config({ @@ -208,7 +209,7 @@ export const chainSchema = z chainId: number, chainName: string ) => { - const provider = new ethers.providers.JsonRpcProvider(rpcUrl); + const provider = getProvider({ rpcUrl, name: chainName, chainId }); // Add provider event listeners for detailed logging provider.on("debug", (info) => { diff --git a/packages/scripts/src/addOrbitChain/transforms.ts b/packages/scripts/src/addOrbitChain/transforms.ts index 184eca0a72..fb2ea5b356 100644 --- a/packages/scripts/src/addOrbitChain/transforms.ts +++ b/packages/scripts/src/addOrbitChain/transforms.ts @@ -4,11 +4,6 @@ import * as core from "@actions/core"; import { warning } from "@actions/core"; import { getArbitrumNetworkInformationFromRollup } from "@arbitrum/sdk"; -import { - JsonRpcProvider, - StaticJsonRpcProvider, - ConnectionInfo, -} from "@ethersproject/providers"; import axios from "axios"; import { fileTypeFromBuffer } from "file-type"; import * as fs from "fs"; @@ -36,6 +31,7 @@ import { validateOrbitChain, validateOrbitChainsList, } from "./schemas"; +import { getProvider } from "./provider"; const SUPPORTED_IMAGE_EXTENSIONS = ["png", "svg", "jpg", "jpeg", "webp"]; const MAX_IMAGE_SIZE_KB = 100; @@ -363,16 +359,6 @@ export const fetchAndSaveImage = async ( return `/${imageSavePath}`; }; -class LoggingProvider extends StaticJsonRpcProvider { - perform(method: string, parameters: any): Promise { - console.log(">>>", method, parameters); - return super.perform(method, parameters).then((result) => { - console.log("<<<", method, parameters, result); - return result; - }); - } -} - export const transformIncomingDataToOrbitChain = async ( chainData: IncomingChainData, chainLogoPath: string, @@ -382,25 +368,7 @@ export const transformIncomingDataToOrbitChain = async ( const isTestnet = TESTNET_PARENT_CHAIN_IDS.includes(parentChainId); const parentChainInfo = getParentChainInfo(parentChainId); console.log("Parent chain info:", parentChainInfo); - - const connection: ConnectionInfo = { - url: parentChainInfo.rpcUrl, - timeout: 30000, - allowGzip: true, - skipFetchSetup: true, - throttleLimit: 3, - throttleSlotInterval: 1000, - headers: { - Accept: "*/*", - "Accept-Encoding": "gzip, deflate, br", - }, - }; - - const provider = new LoggingProvider(connection, { - name: "arbitrum", - chainId: parentChainId, - }); - + const provider = getProvider(parentChainInfo); console.log("Provider:", provider); try { const network = await provider.getNetwork();