From 61ed2bffab81d5d9d80701f579d337192d4fc524 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Tue, 19 Mar 2024 10:48:59 +0100 Subject: [PATCH] cleanup --- examples/opensea.ts | 2 +- src/chains/ethereum.ts | 27 +++++++-------------------- src/index.ts | 8 ++------ 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/examples/opensea.ts b/examples/opensea.ts index cc38d11..d529031 100644 --- a/examples/opensea.ts +++ b/examples/opensea.ts @@ -42,7 +42,7 @@ const run = async (slug: string): Promise => { const tx = data.fulfillment_data.transaction; const input_data = tx.input_data; - + // TODO - report or fix these bugs with OpenseaSDK // @ts-expect-error: Undocumented field on type FulfillmentData within FulfillmentDataResponse const order = input_data.parameters; diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index 5f8ca9e..ec7dfab 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -1,11 +1,10 @@ -import { Common } from "@ethereumjs/common"; import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; import { bytesToHex } from "@ethereumjs/util"; import { BN } from "bn.js"; import { ethers } from "ethers"; import { providers as nearProviders } from "near-api-js"; import { functionCall } from "near-api-js/lib/transaction"; -import { Web3, Bytes } from "web3"; +import { Bytes } from "web3"; import { deriveChildPublicKey, najPublicKeyStrToUncompressedHexPoint, @@ -15,21 +14,7 @@ import { NO_DEPOSIT, getNearAccount, provider as nearProvider } from "./near"; import { GasPriceResponse, GasPrices, TxPayload } from "../types"; import { getMultichainContract } from "../mpc_contract"; import { getFirstNonZeroGasPrice } from "../utils/gasPrice"; - -const config = { - chainId: 11155111, - // providerUrl: "https://rpc.sepolia.ethpandaops.io", - // providerUrl: "https://sepolia.gateway.tenderly.co", - providerUrl: "https://rpc2.sepolia.org", - chain: "sepolia", -}; - -export const web3 = new Web3(config.providerUrl); -export const common = new Common({ chain: config.chain }); -export const provider = new ethers.JsonRpcProvider( - config.providerUrl, - config.chainId -); +import { common, provider, web3 } from "../config"; export const deriveEthAddress = async ( derivationPath: string @@ -47,9 +32,9 @@ export const deriveEthAddress = async ( return uncompressedHexPointToEvmAddress(publicKey); }; -async function queryGasPrice(): Promise { +async function queryGasPrice(network: string): Promise { const res = await fetch( - "https://sepolia.beaconcha.in/api/v1/execution/gasnow" + `https://${network}.beaconcha.in/api/v1/execution/gasnow` ); const gasPrices = (await res.json()) as GasPriceResponse; const maxPriorityFeePerGas = BigInt(getFirstNonZeroGasPrice(gasPrices)!); @@ -72,7 +57,9 @@ export const createPayload = async ( data?: string ): Promise => { const nonce = await provider.getTransactionCount(sender); - const { maxFeePerGas, maxPriorityFeePerGas } = await queryGasPrice(); + const { maxFeePerGas, maxPriorityFeePerGas } = await queryGasPrice( + (await provider.getNetwork()).name + ); const transactionData = { nonce, to: receiver, diff --git a/src/index.ts b/src/index.ts index 8297c29..bcd985e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,2 @@ -import { - deriveEthAddress, - signAndSendTransaction, - web3, -} from "./chains/ethereum"; -export { deriveEthAddress, signAndSendTransaction, web3 }; +import { deriveEthAddress, signAndSendTransaction } from "./chains/ethereum"; +export { deriveEthAddress, signAndSendTransaction };