diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..9f5b1f4 --- /dev/null +++ b/biome.json @@ -0,0 +1,8 @@ +{ + "linter": { + "enabled": true, + "rules": { + "default": true + } + } + } \ No newline at end of file diff --git a/src/api/networks.ts b/src/api/networks.ts index d2ccad3..4a94233 100644 --- a/src/api/networks.ts +++ b/src/api/networks.ts @@ -3,41 +3,40 @@ import { UnimplementedNetwork } from '../error' /** * Network connection presets supported by Flashbots. */ -export class SupportedNetworks { - private static supportedNetworks = { - mainnet: { - name: "mainnet", - chainId: 1, - streamUrl: "https://mev-share.flashbots.net", - apiUrl: "https://relay.flashbots.net" - }, - goerli: { - name: "goerli", - chainId: 5, - streamUrl: "https://mev-share-goerli.flashbots.net", - apiUrl: "https://relay-goerli.flashbots.net" - } +const networks = { + mainnet: { + name: "mainnet", + chainId: 1, + streamUrl: "https://mev-share.flashbots.net", + apiUrl: "https://relay.flashbots.net", + }, + sepolia: { + name: "sepolia", + chainId: 11155111, + streamUrl: "https://mev-share-sepolia.flashbots.net", + apiUrl: "https://relay-sepolia.flashbots.net", + }, + holesky: { + name: "holesky", + chainId: 17000, + streamUrl: "https://mev-share-holesky.flashbots.net", + apiUrl: "https://relay-holesky.flashbots.net", } +} as const - // expose networks individually as class properties - public static mainnet = this.supportedNetworks.mainnet - public static goerli = this.supportedNetworks.goerli - - /** - * Returns true if the given chainId is supported by the client. - */ - static supportsChainId(chainId: number) { - return Object.values(this.supportedNetworks).map(n => n.chainId).includes(chainId) +/** + * Gets the network preset matching the provided chainId, + * throws an UnimplementedNetwork error if not found. + */ +function getNetwork (chainId: number) { + const net = Object.values(networks).find(net => net.chainId === chainId) + if (net) { + return net } + throw new UnimplementedNetwork({chainId}) +} - /** Gets the network preset matching the provided chainId, throws an error if not found. */ - static getNetwork(chainId: number) { - if (this.supportsChainId(chainId)) { - const net = Object.values(this.supportedNetworks).find(net => net.chainId === chainId) - if (net) { - return net - } - } - throw new UnimplementedNetwork({chainId}) - } +export default { + ...networks, + getNetwork, } diff --git a/src/client.ts b/src/client.ts index 4a84a2d..436d1ae 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2,7 +2,6 @@ import axios, { AxiosError } from "axios" import { Transaction, Wallet } from 'ethers' import EventSource from "eventsource" import { JsonRpcError, NetworkFailure, UnimplementedStreamEvent } from './error' - import { getRpcRequest, JsonRpcData } from './flashbots'; import { BundleParams, @@ -24,7 +23,7 @@ import { EventHistoryEntry } from './api/interfaces' import { mungeBundleParams, mungePrivateTxParams, mungeSimBundleOptions } from "./api/mungers" -import { SupportedNetworks } from './api/networks' +import SupportedNetworks from './api/networks' import { PendingBundle, PendingTransaction } from './api/events'; import { URLSearchParams } from 'url'; @@ -45,14 +44,19 @@ export default class MevShareClient { return new MevShareClient(authSigner, SupportedNetworks.mainnet) } - /** Connect to Flashbots MEV-Share node on Goerli. */ - static useEthereumGoerli(authSigner: Wallet): MevShareClient { - return new MevShareClient(authSigner, SupportedNetworks.goerli) + /** Connect to Flashbots MEV-Share node on Sepolia. */ + static useEthereumSepolia(authSigner: Wallet): MevShareClient { + return new MevShareClient(authSigner, SupportedNetworks.sepolia) + } + + /** Connect to Flashbots MEV-Share node on Holesky. */ + static useEthereumHolesky(authSigner: Wallet): MevShareClient { + return new MevShareClient(authSigner, SupportedNetworks.holesky) } /** Connect to supported networks by specifying a network with a `chainId`. */ static fromNetwork(authSigner: Wallet, {chainId}: {chainId: number | bigint}): MevShareClient { - const chainNum = typeof chainId == "bigint" ? Number(chainId) : chainId + const chainNum = typeof chainId === "bigint" ? Number(chainId) : chainId const network = SupportedNetworks.getNetwork(chainNum) return new MevShareClient(authSigner, network) } diff --git a/src/examples/lib/helpers.ts b/src/examples/lib/helpers.ts index 3beefed..e2be1f7 100644 --- a/src/examples/lib/helpers.ts +++ b/src/examples/lib/helpers.ts @@ -1,11 +1,13 @@ -import { JsonRpcProvider, Network, Wallet } from 'ethers' +import { JsonRpcProvider, Wallet } from 'ethers' import MevShareClient from '../..' import Env from './env' +import networks from '../../api/networks' export function getProvider() { - return new JsonRpcProvider(Env.providerUrl, new Network("goerli", 5)) + return new JsonRpcProvider(Env.providerUrl, networks.sepolia) } +/** Initializes wallet and provider for examples, using Sepolia. */ export async function initExample(provider: JsonRpcProvider) { const authSigner = new Wallet(Env.authKey).connect(provider) @@ -13,7 +15,7 @@ export async function initExample(provider: JsonRpcProvider) { provider, wallet: new Wallet(Env.senderKey).connect(provider), authSigner, - mevshare: MevShareClient.useEthereumGoerli(authSigner), + mevshare: MevShareClient.useEthereumSepolia(authSigner), feeData: await provider.getFeeData(), } } diff --git a/src/index.ts b/src/index.ts index effa8eb..2bb3d4e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import SupportedNetworks from './api/networks' import MevShareClient from './client' export { @@ -11,6 +12,6 @@ export { EventHistoryEntry, } from "./api/interfaces" -export {SupportedNetworks} from "./api/networks" +export {SupportedNetworks} export default MevShareClient