Parcourir la source

chore: more linting yak shaving

benduran il y a 3 semaines
Parent
commit
dc0dbf3643

+ 7 - 2
lazer/sdk/js/tsconfig.build.json

@@ -6,5 +6,10 @@
     "declaration": true,
     "isolatedModules": false
   },
-  "exclude": ["node_modules", "dist", "examples/", "**/__tests__/*"]
-}
+  "exclude": [
+    "node_modules",
+    "dist",
+    "examples/",
+    "**/__tests__/*"
+  ]
+}

+ 5 - 0
price_service/client/js/eslint.config.js

@@ -4,4 +4,9 @@ import { globalIgnores } from "eslint/config";
 export default [
   globalIgnores(["src/__tests__/**/*", "src/examples/**/*"]),
   ...base,
+  {
+    rules: {
+      "unicorn/filename-case": "off",
+    },
+  },
 ];

+ 41 - 25
price_service/client/js/src/PriceServiceConnection.ts

@@ -1,8 +1,23 @@
-import { type HexString, PriceFeed } from "@pythnetwork/price-service-sdk";
-import axios, { type AxiosInstance } from "axios";
+/* eslint-disable @typescript-eslint/no-unsafe-member-access */
+/* eslint-disable @typescript-eslint/no-explicit-any */
+/* eslint-disable unicorn/no-process-exit */
+/* eslint-disable n/no-process-exit */
+/* eslint-disable @typescript-eslint/no-non-null-assertion */
+/* eslint-disable @typescript-eslint/restrict-template-expressions */
+/* eslint-disable @typescript-eslint/no-unnecessary-condition */
+/* eslint-disable @typescript-eslint/no-base-to-string */
+/* eslint-disable @typescript-eslint/no-floating-promises */
+/* eslint-disable @typescript-eslint/no-empty-function */
+/* eslint-disable no-console */
+/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
+import type { HexString } from "@pythnetwork/price-service-sdk";
+import { PriceFeed } from "@pythnetwork/price-service-sdk";
+import type { AxiosInstance } from "axios";
+import axios from "axios";
 import axiosRetry from "axios-retry";
 import * as WebSocket from "isomorphic-ws";
-import { type Logger } from "ts-log";
+import type { Logger } from "ts-log";
+
 import { ResilientWebSocket } from "./ResillientWebSocket";
 import { makeWebsocketUrl, removeLeading0xIfExists } from "./utils";
 
@@ -79,8 +94,8 @@ export class PriceServiceConnection {
   /**
    * Constructs a new Connection.
    *
-   * @param endpoint endpoint URL to the price service. Example: https://website/example/
-   * @param config Optional PriceServiceConnectionConfig for custom configurations.
+   * @param endpoint - endpoint URL to the price service. Example: https://website/example/
+   * @param config - Optional PriceServiceConnectionConfig for custom configurations.
    */
   constructor(endpoint: string, config?: PriceServiceConnectionConfig) {
     this.httpClient = axios.create({
@@ -89,7 +104,8 @@ export class PriceServiceConnection {
     });
     axiosRetry(this.httpClient, {
       retries: config?.httpRetries || 3,
-      retryDelay: axiosRetry.exponentialDelay,
+      // eslint-disable-next-line import/no-named-as-default-member
+      retryDelay: axiosRetry.exponentialDelay.bind(axiosRetry),
     });
 
     this.priceFeedRequestConfig = {
@@ -133,7 +149,7 @@ export class PriceServiceConnection {
    * Fetch Latest PriceFeeds of given price ids.
    * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price ids)
    *
-   * @param priceIds Array of hex-encoded price ids.
+   * @param priceIds - Array of hex-encoded price ids.
    * @returns Array of PriceFeeds
    */
   async getLatestPriceFeeds(
@@ -162,7 +178,7 @@ export class PriceServiceConnection {
    *
    * This function is coupled to wormhole implemntation.
    *
-   * @param priceIds Array of hex-encoded price ids.
+   * @param priceIds - Array of hex-encoded price ids.
    * @returns Array of base64 encoded VAAs.
    */
   async getLatestVaas(priceIds: HexString[]): Promise<string[]> {
@@ -171,7 +187,7 @@ export class PriceServiceConnection {
         ids: priceIds,
       },
     });
-    return response.data;
+    return response.data as string[];
   }
 
   /**
@@ -182,8 +198,8 @@ export class PriceServiceConnection {
    *
    * This function is coupled to wormhole implemntation.
    *
-   * @param priceId Hex-encoded price id.
-   * @param publishTime Epoch timestamp in seconds.
+   * @param priceId - Hex-encoded price id.
+   * @param publishTime - Epoch timestamp in seconds.
    * @returns Tuple of VAA and publishTime.
    */
   async getVaa(
@@ -205,8 +221,8 @@ export class PriceServiceConnection {
    * is old and the price service endpoint does not have a db backend for historical requests.
    * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id)
    *
-   * @param priceId Hex-encoded price id.
-   * @param publishTime Epoch timestamp in seconds.
+   * @param priceId - Hex-encoded price id.
+   * @param publishTime - Epoch timestamp in seconds.
    * @returns PriceFeed
    */
   async getPriceFeed(
@@ -233,7 +249,7 @@ export class PriceServiceConnection {
    */
   async getPriceFeedIds(): Promise<HexString[]> {
     const response = await this.httpClient.get("/api/price_feed_ids");
-    return response.data;
+    return response.data as HexString[];
   }
 
   /**
@@ -244,8 +260,8 @@ export class PriceServiceConnection {
    * it calls `connection.onWsError`. If you want to handle the errors you should set the
    * `onWsError` function to your custom error handler.
    *
-   * @param priceIds Array of hex-encoded price ids.
-   * @param cb Callback function that is called with a PriceFeed upon updates to given price ids.
+   * @param priceIds - Array of hex-encoded price ids.
+   * @param cb - Callback function that is called with a PriceFeed upon updates to given price ids.
    */
   async subscribePriceFeedUpdates(
     priceIds: HexString[],
@@ -287,8 +303,8 @@ export class PriceServiceConnection {
    * it calls `connection.onWsError`. If you want to handle the errors you should set the
    * `onWsError` function to your custom error handler.
    *
-   * @param priceIds Array of hex-encoded price ids.
-   * @param cb Optional callback, if set it will only unsubscribe this callback from updates for given price ids.
+   * @param priceIds - Array of hex-encoded price ids.
+   * @param cb - Optional callback, if set it will only unsubscribe this callback from updates for given price ids.
    */
   async unsubscribePriceFeedUpdates(
     priceIds: HexString[],
@@ -353,7 +369,7 @@ export class PriceServiceConnection {
     this.wsClient.onReconnect = () => {
       if (this.priceFeedCallbacks.size > 0) {
         const message: ClientMessage = {
-          ids: Array.from(this.priceFeedCallbacks.keys()),
+          ids: [...this.priceFeedCallbacks.keys()],
           type: "subscribe",
           verbose: this.priceFeedRequestConfig.verbose,
           binary: this.priceFeedRequestConfig.binary,
@@ -372,10 +388,10 @@ export class PriceServiceConnection {
 
       try {
         message = JSON.parse(data.toString()) as ServerMessage;
-      } catch (e: any) {
+      } catch (error: unknown) {
         this.logger.error(`Error parsing message ${data.toString()} as JSON.`);
-        this.logger.error(e);
-        this.onWsError(e);
+        this.logger.error(error);
+        this.onWsError(error as Error);
         return;
       }
 
@@ -390,12 +406,12 @@ export class PriceServiceConnection {
         let priceFeed;
         try {
           priceFeed = PriceFeed.fromJson(message.price_feed);
-        } catch (e: any) {
+        } catch (error: unknown) {
           this.logger.error(
             `Error parsing price feeds from message ${data.toString()}.`,
           );
-          this.logger.error(e);
-          this.onWsError(e);
+          this.logger.error(error);
+          this.onWsError(error as Error);
           return;
         }
 

+ 21 - 12
price_service/client/js/src/ResillientWebSocket.ts

@@ -1,7 +1,16 @@
+/* eslint-disable @typescript-eslint/no-floating-promises */
+/* eslint-disable @typescript-eslint/no-misused-promises */
+/* eslint-disable @typescript-eslint/no-unsafe-argument */
+/* eslint-disable @typescript-eslint/no-non-null-assertion */
+/* eslint-disable @typescript-eslint/no-unnecessary-condition */
+/* eslint-disable unicorn/prefer-add-event-listener */
+/* eslint-disable @typescript-eslint/require-await */
+/* eslint-disable @typescript-eslint/restrict-template-expressions */
+/* eslint-disable @typescript-eslint/no-empty-function */
 import WebSocket from "isomorphic-ws";
-import { type Logger } from "ts-log";
+import type { Logger } from "ts-log";
 
-const PING_TIMEOUT_DURATION = 30000 + 3000; // It is 30s on the server and 3s is added for delays
+const PING_TIMEOUT_DURATION = 30_000 + 3000; // It is 30s on the server and 3s is added for delays
 
 /**
  * This class wraps websocket to provide a resilient web socket client.
@@ -38,7 +47,7 @@ export class ResilientWebSocket {
     this.onReconnect = () => {};
   }
 
-  async send(data: any) {
+  async send(data: unknown) {
     this.logger?.info(`Sending ${data}`);
 
     await this.waitForMaybeReadyWebSocket();
@@ -48,7 +57,7 @@ export class ResilientWebSocket {
         "Couldn't connect to the websocket server. Error callback is called.",
       );
     } else {
-      this.wsClient?.send(data);
+      this.wsClient.send(data as Buffer);
     }
   }
 
@@ -62,13 +71,13 @@ export class ResilientWebSocket {
     this.wsClient = new WebSocket(this.endpoint);
     this.wsUserClosed = false;
 
-    this.wsClient.onopen = () => {
+    this.wsClient.addEventListener("open", () => {
       this.wsFailedAttempts = 0;
       // Ping handler is undefined in browser side so heartbeat is disabled.
       if (this.wsClient!.on !== undefined) {
         this.heartbeat();
       }
-    };
+    });
 
     this.wsClient.onerror = (event) => {
       this.onError(event.error);
@@ -78,12 +87,14 @@ export class ResilientWebSocket {
       this.onMessage(event.data);
     };
 
-    this.wsClient.onclose = async () => {
+    this.wsClient.addEventListener("close", async () => {
       if (this.pingTimeout !== undefined) {
         clearInterval(this.pingTimeout);
       }
 
-      if (this.wsUserClosed === false) {
+      if (this.wsUserClosed) {
+        this.logger?.info("The connection has been closed successfully.");
+      } else {
         this.wsFailedAttempts += 1;
         this.wsClient = undefined;
         const waitTime = expoBackoff(this.wsFailedAttempts);
@@ -94,10 +105,8 @@ export class ResilientWebSocket {
 
         await sleep(waitTime);
         this.restartUnexpectedClosedWebsocket();
-      } else {
-        this.logger?.info("The connection has been closed successfully.");
       }
-    };
+    });
 
     if (this.wsClient.on !== undefined) {
       // Ping handler is undefined in browser side
@@ -144,7 +153,7 @@ export class ResilientWebSocket {
   }
 
   private async restartUnexpectedClosedWebsocket() {
-    if (this.wsUserClosed === true) {
+    if (this.wsUserClosed) {
       return;
     }
 

+ 3 - 7
price_service/client/js/src/utils.ts

@@ -1,9 +1,9 @@
-import { type HexString } from "@pythnetwork/price-service-sdk";
+import type { HexString } from "@pythnetwork/price-service-sdk";
 
 /**
  * Convert http(s) endpoint to ws(s) endpoint.
  *
- * @param endpoint Http(s) protocol endpoint
+ * @param endpoint -  Http(s) protocol endpoint
  * @returns Ws(s) protocol endpoint of the same address
  */
 export function makeWebsocketUrl(endpoint: string) {
@@ -16,9 +16,5 @@ export function makeWebsocketUrl(endpoint: string) {
 }
 
 export function removeLeading0xIfExists(id: HexString): HexString {
-  if (id.startsWith("0x")) {
-    return id.substring(2);
-  } else {
-    return id;
-  }
+  return id.startsWith("0x") ? id.slice(2) : id;
 }

+ 1 - 1
target_chains/aptos/sdk/js/package.json

@@ -75,4 +75,4 @@
     },
     "./package.json": "./package.json"
   }
-}
+}

+ 7 - 5
target_chains/aptos/sdk/js/src/AptosPriceServiceConnection.ts

@@ -1,9 +1,11 @@
+import { Buffer } from "node:buffer";
+
+import type {HexString} from "@pythnetwork/price-service-client";
 import {
-  PriceServiceConnection,
-  type HexString,
+  PriceServiceConnection
+  
 } from "@pythnetwork/price-service-client";
 import { BCS } from "aptos";
-import { Buffer } from "buffer";
 
 export class AptosPriceServiceConnection extends PriceServiceConnection {
   /**
@@ -16,7 +18,7 @@ export class AptosPriceServiceConnection extends PriceServiceConnection {
   async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<number[][]> {
     // Fetch the latest price feed update VAAs from the price service
     const latestVaas = await this.getLatestVaas(priceIds);
-    return latestVaas.map((vaa) => Array.from(Buffer.from(vaa, "base64")));
+    return latestVaas.map((vaa) => [...Buffer.from(vaa, "base64")]);
   }
 
   /**
@@ -27,7 +29,7 @@ export class AptosPriceServiceConnection extends PriceServiceConnection {
   static serializeUpdateData(updateData: number[][]): Uint8Array {
     const serializer = new BCS.Serializer();
     serializer.serializeU32AsUleb128(updateData.length);
-    updateData.forEach((vaa) => serializer.serializeBytes(Buffer.from(vaa)));
+    for (const vaa of updateData) serializer.serializeBytes(Buffer.from(vaa));
     return serializer.getBytes();
   }
 }

+ 1 - 1
target_chains/aptos/sdk/js/src/examples/AptosRelay.ts

@@ -1,8 +1,8 @@
+import { AptosAccount, AptosClient, TxnBuilderTypes } from "aptos";
 import yargs from "yargs";
 import { hideBin } from "yargs/helpers";
 
 import { AptosPriceServiceConnection } from "../index";
-import { AptosAccount, AptosClient, TxnBuilderTypes } from "aptos";
 
 const argv = yargs(hideBin(process.argv))
   .option("price-ids", {

+ 1 - 1
target_chains/sui/sdk/js-iota/eslint.config.js

@@ -2,7 +2,7 @@ import { base } from "@cprussin/eslint-config";
 import { globalIgnores } from "eslint/config";
 
 export default [
-  globalIgnores(["**/schemas/*", "**/__tests__/*"]),
+  globalIgnores(["**/schemas/*", "**/__tests__/*", "**/examples/*"]),
   ...base,
   { rules: { "unicorn/filename-case": "off" } },
 ];

+ 1 - 1
target_chains/sui/sdk/js-iota/package.json

@@ -79,4 +79,4 @@
     "./package.json": "./package.json"
   },
   "module": "./dist/esm/index.js"
-}
+}

+ 5 - 6
target_chains/sui/sdk/js-iota/src/IotaPriceServiceConnection.ts

@@ -1,8 +1,7 @@
-import {
-  PriceServiceConnection,
-  type HexString,
-} from "@pythnetwork/price-service-client";
-import { Buffer } from "buffer";
+import { Buffer } from "node:buffer";
+
+import type { HexString } from "@pythnetwork/price-service-client";
+import { PriceServiceConnection } from "@pythnetwork/price-service-client";
 
 export class IotaPriceServiceConnection extends PriceServiceConnection {
   /**
@@ -10,7 +9,7 @@ export class IotaPriceServiceConnection extends PriceServiceConnection {
    * can be submitted to the Pyth contract to update the prices. This will throw an axios error if there is a network problem or
    * the price service returns a non-ok response (e.g: Invalid price ids)
    *
-   * @param priceIds Array of hex-encoded price ids.
+   * @param priceIds - Array of hex-encoded price ids.
    * @returns Array of buffers containing the price update data.
    */
   async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Buffer[]> {

+ 30 - 22
target_chains/sui/sdk/js-iota/src/client.ts

@@ -1,9 +1,14 @@
+/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
+/* eslint-disable @typescript-eslint/no-non-null-assertion */
+/* eslint-disable @typescript-eslint/no-unsafe-member-access */
+/* eslint-disable no-console */
+import { Buffer } from "node:buffer";
+
+import { bcs } from "@iota/iota-sdk/bcs";
 import { IotaClient } from "@iota/iota-sdk/client";
-import { IOTA_CLOCK_OBJECT_ID } from "@iota/iota-sdk/utils";
 import { Transaction } from "@iota/iota-sdk/transactions";
-import { bcs } from "@iota/iota-sdk/bcs";
-import { type HexString } from "@pythnetwork/price-service-client";
-import { Buffer } from "buffer";
+import { IOTA_CLOCK_OBJECT_ID } from "@iota/iota-sdk/utils";
+import type { HexString } from "@pythnetwork/price-service-client";
 
 const MAX_ARGUMENT_SIZE = 16 * 1024;
 export type ObjectId = string;
@@ -12,7 +17,7 @@ export class IotaPythClient {
   private pythPackageId: ObjectId | undefined;
   private wormholePackageId: ObjectId | undefined;
   private priceTableInfo: { id: ObjectId; fieldType: ObjectId } | undefined;
-  private priceFeedObjectIdCache: Map<HexString, ObjectId> = new Map();
+  private priceFeedObjectIdCache = new Map<HexString, ObjectId>();
   private baseUpdateFee: number | undefined;
   constructor(
     public provider: IotaClient,
@@ -30,8 +35,7 @@ export class IotaPythClient {
         options: { showContent: true },
       });
       if (
-        !result.data ||
-        !result.data.content ||
+        !result.data?.content ||
         result.data.content.dataType !== "moveObject"
       )
         throw new Error("Unable to fetch pyth state object");
@@ -46,7 +50,7 @@ export class IotaPythClient {
   /**
    * getPackageId returns the latest package id that the object belongs to. Use this to
    * fetch the latest package id for a given object id and handle package upgrades automatically.
-   * @param objectId
+   * @param objectId - the object id
    * @returns package id
    */
   async getPackageId(objectId: ObjectId): Promise<ObjectId> {
@@ -69,6 +73,7 @@ export class IotaPythClient {
     if ("upgrade_cap" in state) {
       // eslint-disable-next-line @typescript-eslint/ban-ts-comment
       // @ts-ignore
+      // eslint-disable-next-line @typescript-eslint/no-unsafe-return
       return state.upgrade_cap.fields.package;
     }
 
@@ -77,8 +82,8 @@ export class IotaPythClient {
 
   /**
    * Adds the commands for calling wormhole and verifying the vaas and returns the verified vaas.
-   * @param vaas array of vaas to verify
-   * @param tx transaction block to add commands to
+   * @param vaas - array of vaas to verify
+   * @param tx - transaction block to add commands to
    */
   async verifyVaas(vaas: Buffer[], tx: Transaction) {
     const wormholePackageId = await this.getWormholePackageId();
@@ -91,7 +96,7 @@ export class IotaPythClient {
           tx.pure(
             bcs
               .vector(bcs.U8)
-              .serialize(Array.from(vaa), {
+              .serialize([...vaa], {
                 maxSize: MAX_ARGUMENT_SIZE,
               })
               .toBytes(),
@@ -106,9 +111,9 @@ export class IotaPythClient {
 
   /**
    * Adds the necessary commands for updating the pyth price feeds to the transaction block.
-   * @param tx transaction block to add commands to
-   * @param updates array of price feed updates received from the price service
-   * @param feedIds array of feed ids to update (in hex format)
+   * @param tx - transaction block to add commands to
+   * @param updates - array of price feed updates received from the price service
+   * @param feedIds - array of feed ids to update (in hex format)
    */
   async updatePriceFeeds(
     tx: Transaction,
@@ -132,7 +137,7 @@ export class IotaPythClient {
         tx.pure(
           bcs
             .vector(bcs.U8)
-            .serialize(Array.from(updates[0]!), {
+            .serialize([...updates[0]!], {
               maxSize: MAX_ARGUMENT_SIZE,
             })
             .toBytes(),
@@ -161,7 +166,8 @@ export class IotaPythClient {
         target: `${packageId}::pyth::update_single_price_feed`,
         arguments: [
           tx.object(this.pythStateId),
-          priceUpdatesHotPotato!,
+          // @ts-expect-error - TODO: Fix the mismatched type here
+          priceUpdatesHotPotato,
           tx.object(priceInfoObjectId),
           coins[coinId]!,
           tx.object(IOTA_CLOCK_OBJECT_ID),
@@ -171,7 +177,8 @@ export class IotaPythClient {
     }
     tx.moveCall({
       target: `${packageId}::hot_potato_vector::destroy`,
-      arguments: [priceUpdatesHotPotato!],
+      // @ts-expect-error - TODO: Fix the mismatched type here
+      arguments: [priceUpdatesHotPotato],
       typeArguments: [`${packageId}::price_info::PriceInfo`],
     });
     return priceInfoObjects;
@@ -192,7 +199,7 @@ export class IotaPythClient {
         tx.pure(
           bcs
             .vector(bcs.U8)
-            .serialize(Array.from(updates[0]!), {
+            .serialize([...updates[0]!], {
               maxSize: MAX_ARGUMENT_SIZE,
             })
             .toBytes(),
@@ -225,7 +232,7 @@ export class IotaPythClient {
 
   /**
    * Get the priceFeedObjectId for a given feedId if not already cached
-   * @param feedId
+   * @param feedId - the feed id
    */
   async getPriceFeedObjectId(feedId: HexString): Promise<ObjectId | undefined> {
     const normalizedFeedId = feedId.replace("0x", "");
@@ -236,11 +243,11 @@ export class IotaPythClient {
         name: {
           type: `${fieldType}::price_identifier::PriceIdentifier`,
           value: {
-            bytes: Array.from(Buffer.from(normalizedFeedId, "hex")),
+            bytes: [...Buffer.from(normalizedFeedId, "hex")],
           },
         },
       });
-      if (!result.data || !result.data.content) {
+      if (!result.data?.content) {
         return undefined;
       }
       if (result.data.content.dataType !== "moveObject") {
@@ -250,6 +257,7 @@ export class IotaPythClient {
         normalizedFeedId,
         // eslint-disable-next-line @typescript-eslint/ban-ts-comment
         // @ts-ignore
+        // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
         result.data.content.fields.value,
       );
     }
@@ -269,7 +277,7 @@ export class IotaPythClient {
           value: "price_info",
         },
       });
-      if (!result.data || !result.data.type) {
+      if (!result.data?.type) {
         throw new Error(
           "Price Table not found, contract may not be initialized",
         );

+ 7 - 5
target_chains/sui/sdk/js-iota/src/examples/IotaRelay.ts

@@ -1,10 +1,12 @@
-import yargs from "yargs";
-import { hideBin } from "yargs/helpers";
+import { Buffer } from "node:buffer";
+
 import { IotaClient } from "@iota/iota-sdk/client";
-import { Transaction } from "@iota/iota-sdk/transactions";
 import { Ed25519Keypair } from "@iota/iota-sdk/keypairs/ed25519";
+import { Transaction } from "@iota/iota-sdk/transactions";
+import yargs from "yargs";
+import { hideBin } from "yargs/helpers";
+
 
-import { Buffer } from "buffer";
 import { IotaPythClient } from "../client";
 import { IotaPriceServiceConnection } from "../index";
 
@@ -48,7 +50,7 @@ async function run() {
   const argv = await argvPromise;
 
   // Fetch the latest price feed update data from the Price Service
-  const connection = new IotaPriceServiceConnection(argv["hermes"]);
+  const connection = new IotaPriceServiceConnection(argv.hermes);
   const feeds = argv["feed-id"] as string[];
 
   const provider = getProvider(argv["full-node"]);

+ 1 - 1
target_chains/sui/sdk/js/package.json

@@ -99,4 +99,4 @@
     "./package.json": "./package.json"
   },
   "module": "./dist/esm/index.js"
-}
+}

+ 31 - 24
target_chains/sui/sdk/js/src/client.ts

@@ -1,9 +1,14 @@
+/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
+/* eslint-disable @typescript-eslint/no-unsafe-assignment */
+/* eslint-disable @typescript-eslint/no-non-null-assertion */
+/* eslint-disable no-console */
+import { Buffer } from "node:buffer";
+
+import { bcs } from "@mysten/sui/bcs";
 import { SuiClient } from "@mysten/sui/client";
-import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
 import { Transaction } from "@mysten/sui/transactions";
-import { bcs } from "@mysten/sui/bcs";
-import { type HexString } from "@pythnetwork/hermes-client";
-import { Buffer } from "buffer";
+import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
+import type { HexString } from "@pythnetwork/hermes-client";
 
 const MAX_ARGUMENT_SIZE = 16 * 1024;
 type NestedTransactionResult = {
@@ -16,7 +21,7 @@ export class SuiPythClient {
   private pythPackageId: ObjectId | undefined;
   private wormholePackageId: ObjectId | undefined;
   private priceTableInfo: { id: ObjectId; fieldType: ObjectId } | undefined;
-  private priceFeedObjectIdCache: Map<HexString, ObjectId> = new Map();
+  private priceFeedObjectIdCache = new Map<HexString, ObjectId>();
   private baseUpdateFee: number | undefined;
   constructor(
     public provider: SuiClient,
@@ -34,8 +39,7 @@ export class SuiPythClient {
         options: { showContent: true },
       });
       if (
-        !result.data ||
-        !result.data.content ||
+        !result.data?.content ||
         result.data.content.dataType !== "moveObject"
       )
         throw new Error("Unable to fetch pyth state object");
@@ -50,7 +54,7 @@ export class SuiPythClient {
   /**
    * getPackageId returns the latest package id that the object belongs to. Use this to
    * fetch the latest package id for a given object id and handle package upgrades automatically.
-   * @param objectId
+   * @param objectId - the object id
    * @returns package id
    */
   async getPackageId(objectId: ObjectId): Promise<ObjectId> {
@@ -73,6 +77,7 @@ export class SuiPythClient {
     if ("upgrade_cap" in state) {
       // eslint-disable-next-line @typescript-eslint/ban-ts-comment
       // @ts-ignore
+      // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
       return state.upgrade_cap.fields.package;
     }
 
@@ -81,8 +86,8 @@ export class SuiPythClient {
 
   /**
    * Adds the commands for calling wormhole and verifying the vaas and returns the verified vaas.
-   * @param vaas array of vaas to verify
-   * @param tx transaction block to add commands to
+   * @param vaas - array of vaas to verify
+   * @param tx - transaction block to add commands to
    */
   async verifyVaas(vaas: Buffer[], tx: Transaction) {
     const wormholePackageId = await this.getWormholePackageId();
@@ -95,7 +100,7 @@ export class SuiPythClient {
           tx.pure(
             bcs
               .vector(bcs.U8)
-              .serialize(Array.from(vaa), {
+              .serialize([...vaa], {
                 maxSize: MAX_ARGUMENT_SIZE,
               })
               .toBytes(),
@@ -127,7 +132,7 @@ export class SuiPythClient {
         tx.pure(
           bcs
             .vector(bcs.U8)
-            .serialize(Array.from(updates[0]!), {
+            .serialize([...updates[0]!], {
               maxSize: MAX_ARGUMENT_SIZE,
             })
             .toBytes(),
@@ -143,6 +148,7 @@ export class SuiPythClient {
     tx: Transaction,
     packageId: string,
     feedIds: HexString[],
+    // eslint-disable-next-line @typescript-eslint/no-explicit-any
     priceUpdatesHotPotato: any,
     coins: NestedTransactionResult[],
   ) {
@@ -178,9 +184,9 @@ export class SuiPythClient {
 
   /**
    * Adds the necessary commands for updating the pyth price feeds to the transaction block.
-   * @param tx transaction block to add commands to
-   * @param updates array of price feed updates received from the price service
-   * @param feedIds array of feed ids to update (in hex format)
+   * @param tx - transaction block to add commands to
+   * @param updates - array of price feed updates received from the price service
+   * @param feedIds - array of feed ids to update (in hex format)
    */
   async updatePriceFeeds(
     tx: Transaction,
@@ -211,10 +217,10 @@ export class SuiPythClient {
 
   /**
    * Updates price feeds using the coin input for payment. Coins can be generated by calling splitCoin on tx.gas.
-   * @param tx transaction block to add commands to
-   * @param updates array of price feed updates received from the price service
-   * @param feedIds array of feed ids to update (in hex format)
-   * @param coins array of Coins for payment of update operations
+   * @param tx - transaction block to add commands to
+   * @param updates - array of price feed updates received from the price service
+   * @param feedIds - array of feed ids to update (in hex format)
+   * @param coins - array of Coins for payment of update operations
    */
   async updatePriceFeedsWithCoins(
     tx: Transaction,
@@ -254,7 +260,7 @@ export class SuiPythClient {
         tx.pure(
           bcs
             .vector(bcs.U8)
-            .serialize(Array.from(updates[0]!), {
+            .serialize([...updates[0]!], {
               maxSize: MAX_ARGUMENT_SIZE,
             })
             .toBytes(),
@@ -287,7 +293,7 @@ export class SuiPythClient {
 
   /**
    * Get the priceFeedObjectId for a given feedId if not already cached
-   * @param feedId
+   * @param feedId - the feed id
    */
   async getPriceFeedObjectId(feedId: HexString): Promise<ObjectId | undefined> {
     const normalizedFeedId = feedId.replace("0x", "");
@@ -298,11 +304,11 @@ export class SuiPythClient {
         name: {
           type: `${fieldType}::price_identifier::PriceIdentifier`,
           value: {
-            bytes: Array.from(Buffer.from(normalizedFeedId, "hex")),
+            bytes: [...Buffer.from(normalizedFeedId, "hex")],
           },
         },
       });
-      if (!result.data || !result.data.content) {
+      if (!result.data?.content) {
         return undefined;
       }
       if (result.data.content.dataType !== "moveObject") {
@@ -312,6 +318,7 @@ export class SuiPythClient {
         normalizedFeedId,
         // eslint-disable-next-line @typescript-eslint/ban-ts-comment
         // @ts-ignore
+        // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
         result.data.content.fields.value,
       );
     }
@@ -331,7 +338,7 @@ export class SuiPythClient {
           value: "price_info",
         },
       });
-      if (!result.data || !result.data.type) {
+      if (!result.data?.type) {
         throw new Error(
           "Price Table not found, contract may not be initialized",
         );