Skip to content

Commit b841b2c

Browse files
authored
fix: reduce load on RPC nodes (#7523)
1 parent 6a26349 commit b841b2c

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

apps/cowswap-frontend/src/modules/onchainTransactions/updaters/FinalizeTxUpdater/hooks/usePendingTransactionsContext.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import useNativeCurrency from 'lib/hooks/useNativeCurrency'
1616

1717
import { CheckEthereumTransactions } from '../types'
1818

19-
export function usePendingTransactionsContext(): CheckEthereumTransactions | null {
19+
export function usePendingTransactionsContext(hasPendingTxs: boolean): CheckEthereumTransactions | null {
2020
const config = useConfig()
2121
const { chainId, account } = useWalletInfo()
2222
const safeInfo = useGnosisSafeInfo()
@@ -32,7 +32,7 @@ export function usePendingTransactionsContext(): CheckEthereumTransactions | nul
3232

3333
return useAsyncMemo(
3434
async () => {
35-
if (!lastBlockNumber || !account) return null
35+
if (!lastBlockNumber || !account || !hasPendingTxs) return null
3636

3737
const transactionsCount = await getTransactionCount(config, { address: account })
3838

@@ -66,6 +66,7 @@ export function usePendingTransactionsContext(): CheckEthereumTransactions | nul
6666
cancelOrdersBatch,
6767
getTwapOrderById,
6868
safeInfo,
69+
hasPendingTxs,
6970
],
7071
null,
7172
)

apps/cowswap-frontend/src/modules/onchainTransactions/updaters/FinalizeTxUpdater/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function FinalizeTxUpdater() {
1818

1919
const transactions = useAllTransactionsDetails(shouldCheckFilter)
2020

21-
const params = usePendingTransactionsContext()
21+
const params = usePendingTransactionsContext(transactions.length > 0)
2222

2323
useEffect(() => {
2424
if (!params) return

libs/wallet/src/wagmi/config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,35 @@ let wagmiAdapter: WagmiAdapter | null = null
166166
let reownAppKit: ReturnType<typeof createAppKit> | null = null
167167
let config: Config
168168

169+
// `batch.multicall` collapses concurrent single `useReadContract` calls into one
170+
// multicall3 aggregate3 — the dominant savings for our `eth_call` budget (otherwise
171+
// each singular contract read is its own RPC call).
172+
// `pollingInterval` overrides viem's 4s default so block-driven hooks (BlockNumberProvider,
173+
// useReadContracts refetches) poll once per ~mainnet block time. Cowswap's UX tolerates
174+
// the L2 staleness this introduces because trades settle on the protocol's batch cadence.
175+
const VIEM_CLIENT_TUNING = {
176+
batch: {
177+
multicall: {
178+
wait: 130, // coalescing window in ms
179+
batchSize: 30_000, // calldata size ceiling (30kb)
180+
},
181+
},
182+
// Frequency (in ms) for polling enabled actions & events.
183+
pollingInterval: 12_000,
184+
} as const
185+
169186
if (isSafeIframe) {
170187
// Safe App iframe: no AppKit — use a plain wagmi config with only the Safe connector.
171188
config = createConfig({
189+
...VIEM_CLIENT_TUNING,
172190
connectors,
173-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
174-
chains: SUPPORTED_REOWN_NETWORKS as any,
191+
chains: SUPPORTED_REOWN_NETWORKS,
175192
storage,
176193
transports: wagmiTransports,
177194
})
178195
} else {
179196
wagmiAdapter = new WagmiAdapter({
197+
...VIEM_CLIENT_TUNING,
180198
connectors: connectors as ConstructorParameters<typeof WagmiAdapter>[0]['connectors'],
181199
customRpcUrls,
182200
networks: SUPPORTED_REOWN_NETWORKS,

0 commit comments

Comments
 (0)