From 16a534e609ee478d2b942a9bb9ed94f84f2d270b Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Mon, 26 Feb 2024 08:10:36 +0000 Subject: [PATCH] fix: no network resolved --- build/esbuild-build.ts | 4 ++-- scripts/typescript/generate-permit2-url.ts | 12 ++---------- scripts/typescript/multi-permits.t.ts | 16 ++++++++++++++++ static/scripts/rewards/constants.ts | 5 +++++ static/scripts/rewards/helpers.ts | 7 +++++++ 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 scripts/typescript/multi-permits.t.ts diff --git a/build/esbuild-build.ts b/build/esbuild-build.ts index 6137d6f0..f6dcd5fd 100644 --- a/build/esbuild-build.ts +++ b/build/esbuild-build.ts @@ -14,13 +14,13 @@ export const entries = [...typescriptEntries, ...cssEntries]; const allNetworkUrls: Record = {}; // this flattens all the rpcs into a single object, with key names that match the networkIds. The arrays are just of URLs per network ID. -const blacklist = ["https://xdai-archive.blockscout.com"]; +const blacklist = ["https://xdai-archive.blockscout.com", "https://gnosis.api.onfinality.io/public"]; Object.keys(extraRpcs).forEach((networkId) => { const officialUrls = extraRpcs[networkId].rpcs.filter((rpc) => { if (typeof rpc === "string") { if (blacklist.includes(rpc)) { - return ""; + return null; } else { return rpc; } diff --git a/scripts/typescript/generate-permit2-url.ts b/scripts/typescript/generate-permit2-url.ts index b523bfb4..ff4d4eab 100644 --- a/scripts/typescript/generate-permit2-url.ts +++ b/scripts/typescript/generate-permit2-url.ts @@ -7,13 +7,13 @@ dotenv.config(); const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // same on all chains -generate().catch((error) => { +generateERC20Permit().catch((error) => { console.error(error); verifyEnvironmentVariables(); process.exitCode = 1; }); -async function generate(multi = false) { +export async function generateERC20Permit(multi = false) { const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL); const myWallet = new ethers.Wallet(process.env.UBIQUIBOT_PRIVATE_KEY || "", provider); @@ -70,11 +70,3 @@ async function generate(multi = false) { console.log(); } } - -export async function generateMultiERC20Permits() { - for (let i = 0; i < 5; i++) { - const url = await generate(true); - log.ok("Testing URL:"); - console.log(url); - } -} diff --git a/scripts/typescript/multi-permits.t.ts b/scripts/typescript/multi-permits.t.ts new file mode 100644 index 00000000..71e89574 --- /dev/null +++ b/scripts/typescript/multi-permits.t.ts @@ -0,0 +1,16 @@ +import { generateERC20Permit } from "./generate-permit2-url"; +import { log, verifyEnvironmentVariables } from "./utils"; + +export async function generateMultiERC20Permits() { + for (let i = 0; i < 5; i++) { + const url = await generateERC20Permit(); + log.ok("Testing URL:"); + console.log(url); + } +} + +generateMultiERC20Permits().catch((error) => { + console.error(error); + verifyEnvironmentVariables(); + process.exitCode = 1; +}); diff --git a/static/scripts/rewards/constants.ts b/static/scripts/rewards/constants.ts index ec0bf5a7..b298c161 100644 --- a/static/scripts/rewards/constants.ts +++ b/static/scripts/rewards/constants.ts @@ -8,6 +8,7 @@ export enum NetworkIds { Mainnet = 1, Goerli = 5, Gnosis = 100, + Anvil = 31337, } export enum Tokens { @@ -19,12 +20,14 @@ export const networkNames = { [NetworkIds.Mainnet]: "Ethereum Mainnet", [NetworkIds.Goerli]: "Goerli Testnet", [NetworkIds.Gnosis]: "Gnosis Chain", + [NetworkIds.Anvil]: "http://127.0.0.1:8545", }; export const networkCurrencies: Record = { [NetworkIds.Mainnet]: { symbol: "ETH", decimals: 18 }, [NetworkIds.Goerli]: { symbol: "GoerliETH", decimals: 18 }, [NetworkIds.Gnosis]: { symbol: "XDAI", decimals: 18 }, + [NetworkIds.Anvil]: { symbol: "XDAI", decimals: 18 }, }; export function getNetworkName(networkId?: number) { @@ -39,12 +42,14 @@ export const networkExplorers: Record = { [NetworkIds.Mainnet]: "https://etherscan.io", [NetworkIds.Goerli]: "https://goerli.etherscan.io", [NetworkIds.Gnosis]: "https://gnosisscan.io", + [NetworkIds.Anvil]: "https://gnosisscan.io", }; export const networkRpcs: Record = { [NetworkIds.Mainnet]: ["https://rpc-pay.ubq.fi/v1/mainnet", ...(extraRpcs[NetworkIds.Mainnet] || [])], [NetworkIds.Goerli]: ["https://rpc-pay.ubq.fi/v1/goerli", ...(extraRpcs[NetworkIds.Goerli] || [])], [NetworkIds.Gnosis]: [...(extraRpcs[NetworkIds.Gnosis] || [])], + [NetworkIds.Anvil]: ["http://127.0.0.1:8545", ""], }; export const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; diff --git a/static/scripts/rewards/helpers.ts b/static/scripts/rewards/helpers.ts index a75d2fb8..b9c3896e 100644 --- a/static/scripts/rewards/helpers.ts +++ b/static/scripts/rewards/helpers.ts @@ -40,6 +40,13 @@ export async function getErc20Contract(contractAddress: string, provider: JsonRp } export async function getOptimalProvider(networkId: number) { + if (networkId === 31337) + return new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545", { + name: "http://127.0.0.1:8545", + chainId: 31337, + ensAddress: "", + }); + const promises = networkRpcs[networkId].map(async (baseURL: string) => { try { const startTime = performance.now();