diff --git a/packages/bots/liquidator/src/index.ts b/packages/bots/liquidator/src/index.ts index 8eb40a169a..7a89c8e1c5 100644 --- a/packages/bots/liquidator/src/index.ts +++ b/packages/bots/liquidator/src/index.ts @@ -1,6 +1,6 @@ import { APIGatewayEvent, APIGatewayProxyResult, Context } from "aws-lambda"; import axios from "axios"; -import { createPublicClient, createWalletClient, fallback, Hex, http } from "viem"; +import { createWalletClient, fallback, Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { mode } from "viem/chains"; import { BotType } from "@ionicprotocol/sdk"; @@ -9,6 +9,7 @@ import config from "./config"; import { liquidatePositions } from "./liquidatePositions"; import { logger } from "./logger"; import { setUpSdk } from "./utils"; +import { createIonicPublicClient } from "./utils/client"; const HEARTBEAT_API_URL: any = process.env.UPTIME_LIQUIDATOR_API; @@ -22,10 +23,7 @@ if (typeof HEARTBEAT_API_URL === "undefined") { export const account = privateKeyToAccount(config.adminPrivateKey as Hex); -export const client = createPublicClient({ - chain: mode, - transport: fallback(config.rpcUrls.map((url) => http(url))), -}); +export const client = createIonicPublicClient(mode, config.rpcUrls); export const walletClient = createWalletClient({ account, diff --git a/packages/bots/liquidator/src/justSubmit.ts b/packages/bots/liquidator/src/justSubmit.ts index 5a37b8e3cb..0c15331390 100644 --- a/packages/bots/liquidator/src/justSubmit.ts +++ b/packages/bots/liquidator/src/justSubmit.ts @@ -1,30 +1,19 @@ import { Client, OpportunityParams } from "@pythnetwork/express-relay-evm-js"; import { ionicLiquidatorAbi } from "@ionicprotocol/sdk"; -import { - createPublicClient, - createWalletClient, - encodeAbiParameters, - encodeFunctionData, - fallback, - Hex, - http, -} from "viem"; +import { createWalletClient, encodeAbiParameters, encodeFunctionData, fallback, Hex, http } from "viem"; import { mode } from "viem/chains"; import { privateKeyToAccount } from "viem/accounts"; import config from "./config"; import { logger } from "./logger"; import { setUpSdk } from "./utils"; +import { createIonicPublicClient } from "./utils/client"; (BigInt.prototype as any).toJSON = function () { return this.toString(); }; const account = privateKeyToAccount(config.adminPrivateKey as Hex); -const publicClient = createPublicClient({ - batch: { multicall: { wait: 16 } }, - chain: mode, - transport: fallback(config.rpcUrls.map((url) => http(url))), -}); +const publicClient = createIonicPublicClient(mode, config.rpcUrls); const walletClient = createWalletClient({ account, chain: mode, diff --git a/packages/bots/liquidator/src/runPythLiquidator.ts b/packages/bots/liquidator/src/runPythLiquidator.ts index 5d46fea54b..1dfadb547f 100644 --- a/packages/bots/liquidator/src/runPythLiquidator.ts +++ b/packages/bots/liquidator/src/runPythLiquidator.ts @@ -8,6 +8,7 @@ import { fallback, Hex, http, + type PublicClientConfig, } from "viem"; import { mode } from "viem/chains"; import { privateKeyToAccount } from "viem/accounts"; @@ -26,11 +27,14 @@ const startTime = Math.floor(new Date().getTime() / 1000); }; const account = privateKeyToAccount(config.adminPrivateKey as Hex); -const publicClient = createPublicClient({ +const clientConfig: PublicClientConfig = { batch: { multicall: { wait: 16 } }, chain: mode, transport: fallback(config.rpcUrls.map((url) => http(url))), -}); + cacheTime: 4_000, + pollingInterval: 4_000, +}; +const publicClient = createPublicClient(clientConfig); const walletClient = createWalletClient({ account, chain: mode, diff --git a/packages/bots/liquidator/src/utils/client.ts b/packages/bots/liquidator/src/utils/client.ts new file mode 100644 index 0000000000..c44a73cc9b --- /dev/null +++ b/packages/bots/liquidator/src/utils/client.ts @@ -0,0 +1,13 @@ +import { Chain, createPublicClient, fallback, http, PublicClientConfig } from "viem"; + +export function createIonicPublicClient(chain: Chain, rpcUrls: string[]) { + const config: PublicClientConfig = { + chain, + transport: fallback(rpcUrls.map((url) => http(url))), + batch: { multicall: { wait: 16 } }, + cacheTime: 4_000, + pollingInterval: 4_000, + }; + + return createPublicClient(config); +}