From b4f2daa7267963480a65a24a793bd8f31a88b4b3 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov <18644653+chybisov@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:55:10 +0200 Subject: [PATCH] fix: batch multicall requests (#199) --- src/core/EVM/publicClient.ts | 13 +++++++++---- src/core/Solana/connection.ts | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/core/EVM/publicClient.ts b/src/core/EVM/publicClient.ts index c90d0989..39de6193 100644 --- a/src/core/EVM/publicClient.ts +++ b/src/core/EVM/publicClient.ts @@ -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' @@ -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 = { @@ -43,6 +45,9 @@ export const getPublicClient = async ( publicClients[chainId] = createPublicClient({ chain: chain, transport: fallback(fallbackTransports), + batch: { + multicall: true, + }, }) } diff --git a/src/core/Solana/connection.ts b/src/core/Solana/connection.ts index c044f252..328f3c76 100644 --- a/src/core/Solana/connection.ts +++ b/src/core/Solana/connection.ts @@ -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 => { if (!connection) {