Jelajahi Sumber

fix(solana_utils): fixed build

benduran 3 minggu lalu
induk
melakukan
20b96c5363

+ 37 - 3
target_chains/solana/sdk/js/solana_utils/package.json

@@ -3,8 +3,8 @@
   "version": "0.5.0",
   "description": "Utility functions for Solana",
   "homepage": "https://pyth.network",
-  "main": "lib/index.js",
-  "types": "lib/index.d.ts",
+  "main": "./dist/cjs/index.js",
+  "types": "./dist/cjs/index.d.ts",
   "files": [
     "dist/**/*"
   ],
@@ -57,5 +57,39 @@
     "pnpm": ">=10.19.0"
   },
   "packageManager": "pnpm@10.19.0",
-  "type": "module"
+  "type": "module",
+  "exports": {
+    ".": {
+      "require": {
+        "default": "./dist/cjs/index.js",
+        "types": "./dist/cjs/index.d.ts"
+      },
+      "import": {
+        "default": "./dist/esm/index.js",
+        "types": "./dist/esm/index.d.ts"
+      }
+    },
+    "./jito": {
+      "require": {
+        "default": "./dist/cjs/jito.js",
+        "types": "./dist/cjs/jito.d.ts"
+      },
+      "import": {
+        "default": "./dist/esm/jito.js",
+        "types": "./dist/esm/jito.d.ts"
+      }
+    },
+    "./transaction": {
+      "require": {
+        "default": "./dist/cjs/transaction.js",
+        "types": "./dist/cjs/transaction.d.ts"
+      },
+      "import": {
+        "default": "./dist/esm/transaction.js",
+        "types": "./dist/esm/transaction.d.ts"
+      }
+    },
+    "./package.json": "./package.json"
+  },
+  "module": "./dist/esm/index.js"
 }

+ 2 - 2
target_chains/solana/sdk/js/solana_utils/src/index.ts

@@ -2,9 +2,9 @@ export {
   getSizeOfTransaction,
   getSizeOfCompressedU16,
   TransactionBuilder,
-  InstructionWithEphemeralSigners,
+  type InstructionWithEphemeralSigners,
   PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET,
-  PriorityFeeConfig,
+  type PriorityFeeConfig,
   sendTransactions,
   DEFAULT_PRIORITY_FEE_CONFIG,
 } from "./transaction";

+ 5 - 5
target_chains/solana/sdk/js/solana_utils/src/jito.ts

@@ -1,8 +1,8 @@
-import { dummyLogger, Logger } from "ts-log";
+import { dummyLogger, type Logger } from "ts-log";
 import { Wallet } from "@coral-xyz/anchor";
 import {
   PublicKey,
-  Signer,
+  type Signer,
   SystemProgram,
   TransactionInstruction,
   VersionedTransaction,
@@ -24,7 +24,7 @@ export const TIP_ACCOUNTS = [
 
 export function getRandomTipAccount(): PublicKey {
   const randomInt = Math.floor(Math.random() * TIP_ACCOUNTS.length);
-  return new PublicKey(TIP_ACCOUNTS[randomInt]);
+  return new PublicKey(TIP_ACCOUNTS[randomInt] ?? '');
 }
 
 export function buildJitoTipInstruction(
@@ -79,7 +79,7 @@ export async function sendTransactionsJito(
   }
 
   const firstTransactionSignature = bs58.encode(
-    signedTransactions[0].signatures[0],
+    signedTransactions[0]?.signatures[0]!,
   );
 
   const bundle = new Bundle(signedTransactions, 2);
@@ -94,7 +94,7 @@ export async function sendTransactionsJito(
       totalAttempts++;
 
       try {
-        await currentClient.sendBundle(bundle);
+        await currentClient?.sendBundle(bundle);
         logger.info(
           { clientIndex: i, totalAttempts },
           `Successfully sent bundle to Jito client after ${totalAttempts} attempts`,

+ 8 - 8
target_chains/solana/sdk/js/solana_utils/src/transaction.ts

@@ -4,8 +4,8 @@ import {
   Connection,
   PACKET_DATA_SIZE,
   PublicKey,
-  SignatureResult,
-  Signer,
+  type SignatureResult,
+  type Signer,
   Transaction,
   TransactionInstruction,
   TransactionMessage,
@@ -40,7 +40,7 @@ export type InstructionWithEphemeralSigners = {
   /** The ephemeral signers that need to sign the transaction where this instruction will be */
   signers: Signer[];
   /** The compute units that this instruction requires, useful if greater than `DEFAULT_COMPUTE_BUDGET_UNITS`  */
-  computeUnits?: number;
+  computeUnits?: number | undefined;
 };
 
 /**
@@ -188,9 +188,9 @@ export class TransactionBuilder {
     } else {
       const sizeWithComputeUnits = getSizeOfTransaction(
         [
-          ...this.transactionInstructions[
+          ...(this.transactionInstructions[
             this.transactionInstructions.length - 1
-          ].instructions,
+          ]?.instructions ?? []),
           instruction,
           this.transactionInstructions.length % JITO_BUNDLE_SIZE === 0 // This transaction may be the first of a Jito bundle, so we leave room for a Jito tip transfer.
             ? buildJitoTipInstruction(this.payer, 1)
@@ -205,13 +205,13 @@ export class TransactionBuilder {
       if (sizeWithComputeUnits <= PACKET_DATA_SIZE) {
         this.transactionInstructions[
           this.transactionInstructions.length - 1
-        ].instructions.push(instruction);
+        ]?.instructions.push(instruction);
         this.transactionInstructions[
           this.transactionInstructions.length - 1
-        ].signers.push(...signers);
+        ]?.signers.push(...signers);
         this.transactionInstructions[
           this.transactionInstructions.length - 1
-        ].computeUnits += computeUnits ?? 0;
+        ]!.computeUnits += computeUnits ?? 0;
       } else
         this.transactionInstructions.push({
           instructions: [instruction],

+ 2 - 1
target_chains/solana/sdk/js/solana_utils/tsconfig.build.json

@@ -3,7 +3,8 @@
   "compilerOptions": {
     "noEmit": false,
     "incremental": false,
-    "declaration": true
+    "declaration": true,
+    "isolatedModules": false
   },
   "exclude": [
     "node_modules",

+ 4 - 0
target_chains/solana/sdk/js/solana_utils/tsconfig.json

@@ -1,4 +1,8 @@
 {
   "extends": "@cprussin/tsconfig/base.json",
+  "compilerOptions": {
+    "moduleResolution": "bundler",
+    "module": "preserve"
+  },
   "exclude": ["dist", "node_modules"]
 }