Skip to content

Commit

Permalink
adds getProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Oct 30, 2024
1 parent 8c756de commit 5a06672
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
37 changes: 37 additions & 0 deletions packages/scripts/src/addOrbitChain/provider.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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;
};
3 changes: 2 additions & 1 deletion packages/scripts/src/addOrbitChain/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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) => {
Expand Down
36 changes: 2 additions & 34 deletions packages/scripts/src/addOrbitChain/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -363,16 +359,6 @@ export const fetchAndSaveImage = async (
return `/${imageSavePath}`;
};

class LoggingProvider extends StaticJsonRpcProvider {
perform(method: string, parameters: any): Promise<any> {
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,
Expand All @@ -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();
Expand Down

0 comments on commit 5a06672

Please sign in to comment.