Skip to content

Commit

Permalink
add new rpc for events
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammedea committed Mar 20, 2024
1 parent 422a938 commit b83b17f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ export const DEXES_TO_EXCLUDE = [
]

export const EVENT_FETCH_RPC_URLS = {
[ChainId.MAINNET]: 'https://celo-mainnet.infura.io/v3/801f4c55ea6b48b4b629c9645964eaa9',
[ChainId.ALFAJORES]: '',
[ChainId.BAKLAVA]: '',
[ChainId.MAINNET]: [
'https://celo-mainnet.infura.io/v3/801f4c55ea6b48b4b629c9645964eaa9',
'https://rpc.ankr.com/celo',
],
[ChainId.ALFAJORES]: [''],
[ChainId.BAKLAVA]: [''],
}
2 changes: 1 addition & 1 deletion src/pages/Earn/useFarmRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const pairDataGql = gql`
}
`
const COMPOUNDS_PER_YEAR = 2
const LAST_N_BLOCKS = 5760 // Last 8 hours
const LAST_N_BLOCKS = 1440 // Last 8 hours

export interface WarningInfo {
poolName: string
Expand Down
12 changes: 8 additions & 4 deletions src/utils/fetchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ async function eventFetcher<T>(

const promises = [contract.queryFilter(filter, fromBlockOrBlockhash, toBlock)]

const alternativeRpc = EVENT_FETCH_RPC_URLS[chainId as ChainId]
if (alternativeRpc) {
const alternativeProvider = new JsonRpcProvider(alternativeRpc)
promises.push(contract.connect(alternativeProvider).queryFilter(filter, fromBlockOrBlockhash, toBlock))
const alternativeRpcs = EVENT_FETCH_RPC_URLS[chainId as ChainId]
if (alternativeRpcs.length > 0) {
for (const rpcUrl of alternativeRpcs) {
if (rpcUrl) {
const alternativeProvider = new JsonRpcProvider(rpcUrl)
promises.push(contract.connect(alternativeProvider).queryFilter(filter, fromBlockOrBlockhash, toBlock))
}
}
}
const result = await Promise.any<Event[]>(promises)
return result as unknown as T[]
Expand Down

0 comments on commit b83b17f

Please sign in to comment.