diff --git a/src/rpcSwitcher/store/rpcSwitcherSlice.ts b/src/rpcSwitcher/store/rpcSwitcherSlice.ts index 6a65ceff..f71c58ac 100644 --- a/src/rpcSwitcher/store/rpcSwitcherSlice.ts +++ b/src/rpcSwitcher/store/rpcSwitcherSlice.ts @@ -10,7 +10,7 @@ import { Chain, createPublicClient, fallback, http } from 'viem'; import { TransactionsSlice } from '../../transactions/store/transactionsSlice'; import { appConfig } from '../../utils/appConfig'; -import { initialRpcUrls, setChain } from '../../utils/chains'; +import { fallBackConfig, initialRpcUrls, setChain } from '../../utils/chains'; import { chainInfoHelper } from '../../utils/configs'; import { getLocalStorageRpcUrls, @@ -105,11 +105,16 @@ export const createRpcSwitcherSlice: StoreSlice< chain, parsedRpcUrlsFromStorage[chainIdNumber].rpcUrl, ) as Draft, - transport: fallback([ - http(parsedRpcUrlsFromStorage[chainIdNumber].rpcUrl), - ...initialRpcUrls[chainIdNumber].map((url) => http(url)), - ]), - }) as Draft, + transport: fallback( + [ + http(parsedRpcUrlsFromStorage[chainIdNumber].rpcUrl), + ...initialRpcUrls[chainIdNumber].map((url) => + http(url), + ), + ], + fallBackConfig, + ), + }), }; } }); @@ -153,13 +158,20 @@ export const createRpcSwitcherSlice: StoreSlice< set((state) => produce(state, (draft) => { draft.appClients[chainId].rpcUrl = rpcUrl; + // @ts-ignore draft.appClients[chainId].instance = createPublicClient({ batch: { multicall: true, }, chain: chainInfoHelper.getChainParameters(chainId), - transport: http(rpcUrl), - }) as Draft; + transport: fallback( + [ + http(rpcUrl), + ...initialRpcUrls[chainId].map((url) => http(url)), + ], + fallBackConfig, + ), + }); }), ); }); @@ -259,8 +271,11 @@ export const createRpcSwitcherSlice: StoreSlice< multicall: true, }, chain: chainInfoHelper.getChainParameters(chainId), - transport: http(rpcUrl), - }) as PublicClient; + transport: fallback( + [http(rpcUrl), ...initialRpcUrls[chainId].map((url) => http(url))], + fallBackConfig, + ), + }); const contractAddresses = appConfig.payloadsControllerConfig[chainId].contractAddresses; diff --git a/src/utils/chains.ts b/src/utils/chains.ts index 2effa4ec..57c00a5a 100644 --- a/src/utils/chains.ts +++ b/src/utils/chains.ts @@ -16,13 +16,27 @@ import { sepolia, } from 'viem/chains'; +export const fallBackConfig = { + rank: { + interval: 100_000, + sampleCount: 2, + timeout: 1000, + weights: { + latency: 0.2, + stability: 0.8, + }, + }, + retryDelay: 100, + retryCount: 5, +}; + // chains RPC urls export const initialRpcUrls: Record = { [mainnet.id]: [ 'https://eth.llamarpc.com', - 'https://ethereum.publicnode.com', 'https://cloudflare-eth.com', 'https://rpc.mevblocker.io', + 'https://blissful-purple-sky.quiknode.pro/9b017a577737f118a5b3ea41790e2dec4aabf393', ], [polygon.id]: [ 'https://polygon.blockpi.network/v1/rpc/public', diff --git a/src/utils/initialClients.ts b/src/utils/initialClients.ts index 65c7613d..a3c4490f 100644 --- a/src/utils/initialClients.ts +++ b/src/utils/initialClients.ts @@ -2,7 +2,7 @@ import { PublicClient } from '@wagmi/core'; import { createPublicClient, fallback, http } from 'viem'; import { appUsedNetworks } from './appConfig'; -import { CHAINS, initialRpcUrls } from './chains'; +import { CHAINS, fallBackConfig, initialRpcUrls } from './chains'; export const initialClients: Record = {}; appUsedNetworks.forEach((chain) => { @@ -11,6 +11,9 @@ appUsedNetworks.forEach((chain) => { multicall: true, }, chain: CHAINS[chain], - transport: fallback(initialRpcUrls[chain].map((url) => http(url))), + transport: fallback( + initialRpcUrls[chain].map((url) => http(url)), + fallBackConfig, + ), }); }); diff --git a/src/web3/services/delegationService.ts b/src/web3/services/delegationService.ts index 5d9c99ff..5cdba851 100644 --- a/src/web3/services/delegationService.ts +++ b/src/web3/services/delegationService.ts @@ -56,7 +56,9 @@ export class DelegationService { } async getUserPowers(userAddress: Hex, underlyingAssets: Hex[]) { - const blockNumber = await this.clients[appConfig.govCoreChainId].getBlock(); + const blockNumber = await this.clients[appConfig.govCoreChainId].getBlock({ + blockTag: 'safe', + }); const contracts = underlyingAssets.map((asset) => { return { @@ -121,9 +123,10 @@ export class DelegationService { }; }; - const totalPowers = await contract.contract.read.getPowersCurrent([ - userAddress, - ]); + const totalPowers = await contract.contract.read.getPowersCurrent( + [userAddress], + { blockNumber: blockNumber.number }, + ); const proposition = getPower( totalPowers[1],