Skip to content

Commit

Permalink
liquidator fix
Browse files Browse the repository at this point in the history
  • Loading branch information
amish kohli authored and amish kohli committed Dec 19, 2024
1 parent f2309e6 commit f3972d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
8 changes: 3 additions & 5 deletions packages/bots/liquidator/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;

Check warning on line 14 in packages/bots/liquidator/src/index.ts

View workflow job for this annotation

GitHub Actions / lint-bots

Unexpected any. Specify a different type

Expand All @@ -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,
Expand Down
17 changes: 3 additions & 14 deletions packages/bots/liquidator/src/justSubmit.ts
Original file line number Diff line number Diff line change
@@ -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 () {

Check warning on line 12 in packages/bots/liquidator/src/justSubmit.ts

View workflow job for this annotation

GitHub Actions / lint-bots

Unexpected any. Specify a different type
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,
Expand Down
8 changes: 6 additions & 2 deletions packages/bots/liquidator/src/runPythLiquidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
fallback,
Hex,
http,
type PublicClientConfig,
} from "viem";
import { mode } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions packages/bots/liquidator/src/utils/client.ts
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit f3972d2

Please sign in to comment.