Skip to content

Commit

Permalink
Merge pull request #3911 from CrocSwap/fix-sepolia-rpc
Browse files Browse the repository at this point in the history
fix sepolia rpc endpoint
  • Loading branch information
benwolski authored Jul 22, 2024
2 parents 9c02cc3 + 46ee2ac commit 8610147
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/ambient-utils/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export const SCROLL_RPC_URL =
? import.meta.env.VITE_SCROLL_RPC_URL
: 'https://rpc.scroll.io/';

export const SEPOLIA_RPC_URL =
import.meta.env.VITE_SEPOLIA_RPC_URL !== undefined
? import.meta.env.VITE_SEPOLIA_RPC_URL
: 'https://ethereum-sepolia-rpc.publicnode.com';

export const ALCHEMY_API_KEY =
import.meta.env.VITE_ALCHEMY_API_KEY !== undefined
? import.meta.env.VITE_ALCHEMY_API_KEY
Expand Down
13 changes: 7 additions & 6 deletions src/ambient-utils/constants/networks/ethereumSepolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import { GCGO_TESTNET_URL } from '../gcgo';
import { Provider } from 'ethers';
import { bigIntToFloat } from '@crocswap-libs/sdk';

const PROVIDER_KEY =
import.meta.env.NODE_ENV === 'test'
? import.meta.env.PROVIDER_KEY
: import.meta.env.VITE_INFURA_KEY;
// const PROVIDER_KEY =
// import.meta.env.NODE_ENV === 'test'
// ? import.meta.env.PROVIDER_KEY
// : import.meta.env.VITE_INFURA_KEY;

const chain = {
chainId: 11155111,
name: 'Sepolia',
currency: 'ETH',
rpcUrl: 'https://rpc.sepolia.org',
rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
explorerUrl: 'https://sepolia.etherscan.io',
};

export const ethereumSepolia: NetworkIF = {
chainId: '0xaa36a7',
graphCacheUrl: GCGO_TESTNET_URL,
evmRpcUrl: 'https://sepolia.infura.io/v3/' + PROVIDER_KEY,
evmRpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
// evmRpcUrl: 'https://sepolia.infura.io/v3/' + PROVIDER_KEY,
chain: chain,
shouldPollBlock: false,
marketData: '0x1',
Expand Down
13 changes: 8 additions & 5 deletions src/contexts/ChainDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IS_LOCAL_ENV,
MAINNET_RPC_URL,
SCROLL_RPC_URL,
SEPOLIA_RPC_URL,
SHOULD_NON_CANDLE_SUBSCRIPTIONS_RECONNECT,
supportedNetworks,
} from '../ambient-utils/constants';
Expand Down Expand Up @@ -124,11 +125,13 @@ export const ChainDataContextProvider = (props: {
async function pollBlockNum(): Promise<void> {
const nodeUrl = ['0x1'].includes(chainData.chainId)
? MAINNET_RPC_URL
: ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
? BLAST_RPC_URL
: ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
? SCROLL_RPC_URL
: blockPollingUrl;
: ['0xaa36a7'].includes(chainData.chainId)
? SEPOLIA_RPC_URL
: ['0x13e31'].includes(chainData.chainId) // use blast env variable for blast network
? BLAST_RPC_URL
: ['0x82750'].includes(chainData.chainId) // use scroll env variable for scroll network
? SCROLL_RPC_URL
: blockPollingUrl;
// const nodeUrl =
// chainData.nodeUrl.toLowerCase().includes('infura') &&
// import.meta.env.VITE_INFURA_KEY
Expand Down
16 changes: 11 additions & 5 deletions src/contexts/CrocEnvContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getDefaultPairForChain,
BLAST_RPC_URL,
MAINNET_RPC_URL,
SEPOLIA_RPC_URL,
SCROLL_RPC_URL,
} from '../ambient-utils/constants';
import { UserDataContext } from './UserDataContext';
Expand Down Expand Up @@ -77,6 +78,9 @@ const scrollProvider = new BatchedJsonRpcProvider(SCROLL_RPC_URL, 534352, {
const blastProvider = new BatchedJsonRpcProvider(BLAST_RPC_URL, 81457, {
staticNetwork: true,
});
const sepoliaProvider = new BatchedJsonRpcProvider(SEPOLIA_RPC_URL, 11155111, {
staticNetwork: true,
});

export const CrocEnvContextProvider = (props: { children: ReactNode }) => {
const { cachedFetchTokenPrice } = useContext(CachedDataContext);
Expand Down Expand Up @@ -195,11 +199,13 @@ export const CrocEnvContextProvider = (props: { children: ReactNode }) => {
? scrollProvider
: chainData.chainId === '0x13e31'
? blastProvider
: new BatchedJsonRpcProvider(
nodeUrl,
parseInt(chainData.chainId),
{ staticNetwork: true },
),
: chainData.chainId === '0xaa36a7'
? sepoliaProvider
: new BatchedJsonRpcProvider(
nodeUrl,
parseInt(chainData.chainId),
{ staticNetwork: true },
),
[chainData.chainId],
);

Expand Down

0 comments on commit 8610147

Please sign in to comment.