Skip to content

Commit

Permalink
fix: batch multicall requests (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov authored Jul 18, 2024
1 parent 33dfda0 commit b4f2daa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/core/EVM/publicClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChainId } from '@lifi/types'
import type { PublicClient } from 'viem'
import { createPublicClient, fallback, http } from 'viem'
import { createPublicClient, fallback, http, webSocket } from 'viem'
import { mainnet, type Chain } from 'viem/chains'
import { config } from '../../config.js'
import { getRpcUrls } from '../rpc.js'
Expand All @@ -19,9 +19,11 @@ export const getPublicClient = async (
if (!publicClients[chainId]) {
const urls = await getRpcUrls(chainId)
const fallbackTransports = urls.map((url) =>
http(url, {
batch: true,
})
url.startsWith('wss')
? webSocket(url)
: http(url, {
batch: true,
})
)
const _chain = await config.getChainById(chainId)
const chain: Chain = {
Expand All @@ -43,6 +45,9 @@ export const getPublicClient = async (
publicClients[chainId] = createPublicClient({
chain: chain,
transport: fallback(fallbackTransports),
batch: {
multicall: true,
},
})
}

Expand Down
5 changes: 2 additions & 3 deletions src/core/Solana/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { getRpcUrl } from '../rpc.js'
let connection: Connection | undefined = undefined

/**
* getSolanaConnection is just a thin wrapper around getting the
* connection (rpc provider) for Solana
* @returns - Solana rpc connection
* getSolanaConnection is just a thin wrapper around getting the connection (RPC provider) for Solana
* @returns - Solana RPC connection
*/
export const getSolanaConnection = async (): Promise<Connection> => {
if (!connection) {
Expand Down

0 comments on commit b4f2daa

Please sign in to comment.