UNPKG

pumpdotfun-sdk-repumped

Version:

Pumpfun SDK — create, buy, sell tokens with support for Jito bundles and multiple relayer integrations. Rebuilt and fixed pumpdotfun-sdk.

1 lines 8.01 kB
{"version":3,"file":"JitoModule.cjs","sources":["../../../../src/modules/JitoModule.ts"],"sourcesContent":["import {\r\n searcherClient,\r\n SearcherClient,\r\n} from \"jito-ts/dist/sdk/block-engine/searcher.js\";\r\nimport { PumpFunSDK } from \"../PumpFunSDK.js\";\r\nimport {\r\n Commitment,\r\n Finality,\r\n Keypair,\r\n PublicKey,\r\n SystemProgram,\r\n Transaction,\r\n VersionedTransaction,\r\n} from \"@solana/web3.js\";\r\nimport { DEFAULT_COMMITMENT, DEFAULT_FINALITY } from \"../pumpFun.consts.js\";\r\nimport {\r\n JitoResult,\r\n PriorityFee,\r\n TransactionResult,\r\n} from \"../pumpFun.types.js\";\r\nimport {\r\n calculateWithSlippageBuy,\r\n calculateWithSlippageSell,\r\n} from \"../slippage.js\";\r\nimport { buildSignedTx, sendTx } from \"../tx.js\";\r\nimport { getRandomJitoTipAccount } from \"./utils.js\";\r\nimport { Bundle } from \"jito-ts/dist/sdk/block-engine/types.js\";\r\n\r\nexport class JitoModule {\r\n private client: SearcherClient;\r\n constructor(\r\n private sdk: PumpFunSDK,\r\n endpoint?: string,\r\n authKeypair?: Keypair\r\n ) {\r\n if (!endpoint) {\r\n throw new Error(\"Jito endpoint is required\");\r\n }\r\n this.client = searcherClient(endpoint, authKeypair);\r\n }\r\n\r\n async buyJito(\r\n buyer: Keypair,\r\n mint: PublicKey,\r\n buyAmountSol: bigint,\r\n slippageBasisPoints: bigint = 500n,\r\n jitoTip: number = 500000,\r\n priorityFees?: PriorityFee,\r\n commitment: Commitment = DEFAULT_COMMITMENT\r\n ): Promise<TransactionResult> {\r\n const bondingAccount = await this.sdk.token.getBondingCurveAccount(\r\n mint,\r\n commitment\r\n );\r\n if (!bondingAccount) {\r\n throw new Error(`Bonding curve account not found: ${mint.toBase58()}`);\r\n }\r\n\r\n const buyAmount = bondingAccount.getBuyPrice(buyAmountSol);\r\n const buyAmountWithSlippage = calculateWithSlippageBuy(\r\n buyAmountSol,\r\n slippageBasisPoints\r\n );\r\n\r\n const transaction = new Transaction();\r\n await this.sdk.trade.buildBuyIx(\r\n buyer.publicKey,\r\n mint,\r\n buyAmount,\r\n buyAmountWithSlippage,\r\n transaction,\r\n commitment,\r\n false\r\n );\r\n this.addJitoTip(buyer, transaction, jitoTip);\r\n const signedTx = await buildSignedTx(\r\n priorityFees,\r\n transaction,\r\n this.sdk.connection,\r\n buyer.publicKey,\r\n commitment,\r\n [buyer]\r\n );\r\n return await this.sendJitoTx(signedTx);\r\n }\r\n\r\n async sellJito(\r\n seller: Keypair,\r\n mint: PublicKey,\r\n sellTokenAmount: bigint,\r\n slippageBasisPoints: bigint = 500n,\r\n jitoTip: number = 500000,\r\n priorityFees?: PriorityFee,\r\n commitment: Commitment = DEFAULT_COMMITMENT\r\n ): Promise<TransactionResult> {\r\n const bondingAccount = await this.sdk.token.getBondingCurveAccount(\r\n mint,\r\n commitment\r\n );\r\n if (!bondingAccount)\r\n throw new Error(`Bonding curve account not found: ${mint.toBase58()}`);\r\n\r\n const globalAccount = await this.sdk.token.getGlobalAccount(commitment);\r\n\r\n const minSolOutput = bondingAccount.getSellPrice(\r\n sellTokenAmount,\r\n globalAccount.feeBasisPoints\r\n );\r\n let sellAmountWithSlippage = calculateWithSlippageSell(\r\n minSolOutput,\r\n slippageBasisPoints\r\n );\r\n if (sellAmountWithSlippage < 1n) sellAmountWithSlippage = 1n;\r\n\r\n const transaction = new Transaction();\r\n await this.sdk.trade.buildSellIx(\r\n seller.publicKey,\r\n mint,\r\n sellTokenAmount,\r\n sellAmountWithSlippage,\r\n transaction,\r\n commitment\r\n );\r\n\r\n this.addJitoTip(seller, transaction, jitoTip);\r\n const signedTx = await buildSignedTx(\r\n priorityFees,\r\n transaction,\r\n this.sdk.connection,\r\n seller.publicKey,\r\n commitment,\r\n [seller]\r\n );\r\n return await this.sendJitoTx(signedTx);\r\n }\r\n\r\n private addJitoTip(\r\n buyer: Keypair,\r\n transaction: Transaction,\r\n jitoTip: number = 500000\r\n ): Transaction {\r\n if (jitoTip <= 0) {\r\n return transaction;\r\n }\r\n const jitoTipAccount = getRandomJitoTipAccount();\r\n const jitoTipInstruction = SystemProgram.transfer({\r\n fromPubkey: buyer.publicKey,\r\n toPubkey: jitoTipAccount,\r\n lamports: jitoTip,\r\n });\r\n transaction.add(jitoTipInstruction);\r\n return transaction;\r\n }\r\n\r\n private async sendJitoTx(tx: VersionedTransaction): Promise<JitoResult> {\r\n const b = new Bundle([tx], 1);\r\n\r\n const res = await this.client.sendBundle(b);\r\n if (res.ok) {\r\n return {\r\n success: true,\r\n bundleId: res.value,\r\n };\r\n }\r\n return {\r\n success: false,\r\n error: res.error,\r\n };\r\n }\r\n}\r\n"],"names":["searcherClient","DEFAULT_COMMITMENT","calculateWithSlippageBuy","Transaction","buildSignedTx","calculateWithSlippageSell","getRandomJitoTipAccount","SystemProgram","Bundle"],"mappings":";;;;;;;;;;MA4Ba,UAAU,CAAA;AAGX,IAAA,GAAA;AAFF,IAAA,MAAM;AACd,IAAA,WAAA,CACU,GAAe,EACvB,QAAiB,EACjB,WAAqB,EAAA;QAFb,IAAA,CAAA,GAAG,GAAH,GAAG;QAIX,IAAI,CAAC,QAAQ,EAAE;AACb,YAAA,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC;;QAE9C,IAAI,CAAC,MAAM,GAAGA,0BAAc,CAAC,QAAQ,EAAE,WAAW,CAAC;;AAGrD,IAAA,MAAM,OAAO,CACX,KAAc,EACd,IAAe,EACf,YAAoB,EACpB,mBAAA,GAA8B,IAAI,EAClC,OAAA,GAAkB,MAAM,EACxB,YAA0B,EAC1B,aAAyBC,iCAAkB,EAAA;AAE3C,QAAA,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sBAAsB,CAChE,IAAI,EACJ,UAAU,C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