pumpdotfun-repumped-sdk
Version:
Pumpfun SDK — create, buy, sell tokens with support for Jito bundles and multiple relayer integrations. Rebuilt and fixed pumpdotfun-sdk.
1 lines • 9.84 kB
Source Map (JSON)
{"version":3,"file":"AstraModule.cjs","sources":["../../../../src/modules/AstraModule.ts"],"sourcesContent":["import { PumpFunSDK } from \"../PumpFunSDK.js\";\r\nimport {\r\n Commitment,\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, getHealthBody } from \"../pumpFun.consts.js\";\r\nimport { PriorityFee, Region } from \"../pumpFun.types.js\";\r\nimport {\r\n calculateWithSlippageBuy,\r\n calculateWithSlippageSell,\r\n} from \"../slippage.js\";\r\nimport { buildSignedTx } from \"../tx.js\";\r\nimport AgentRegistry from \"../AgentRegistry.js\";\r\n\r\nexport class AstraModule {\r\n private key: string;\r\n constructor(private sdk: PumpFunSDK, region: Region, key: string) {\r\n AgentRegistry.registerInConfig(\"astra\", region);\r\n this.key = key;\r\n }\r\n\r\n ASTRA_ACCOUNTS = [\r\n new PublicKey(\"astrazznxsGUhWShqgNtAdfrzP2G83DzcWVJDxwV9bF\"),\r\n new PublicKey(\"astra4uejePWneqNaJKuFFA8oonqCE1sqF6b45kDMZm\"),\r\n new PublicKey(\"astra9xWY93QyfG6yM8zwsKsRodscjQ2uU2HKNL5prk\"),\r\n new PublicKey(\"astraRVUuTHjpwEVvNBeQEgwYx9w9CFyfxjYoobCZhL\"),\r\n ];\r\n\r\n private getRandomAccount() {\r\n const randomIndex = Math.floor(Math.random() * this.ASTRA_ACCOUNTS.length);\r\n return this.ASTRA_ACCOUNTS[randomIndex];\r\n }\r\n\r\n async buy(\r\n buyer: Keypair,\r\n mint: PublicKey,\r\n buyAmountSol: bigint,\r\n slippageBasisPoints: bigint = 500n,\r\n tip: number = 500000,\r\n priorityFees?: PriorityFee,\r\n commitment: Commitment = DEFAULT_COMMITMENT\r\n ): Promise<string> {\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.addTip(buyer, transaction, tip);\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.sendTransaction(signedTx);\r\n }\r\n\r\n async sell(\r\n seller: Keypair,\r\n mint: PublicKey,\r\n sellTokenAmount: bigint,\r\n slippageBasisPoints: bigint = 500n,\r\n tip: number = 500000,\r\n priorityFees?: PriorityFee,\r\n commitment: Commitment = DEFAULT_COMMITMENT\r\n ): Promise<string> {\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.addTip(seller, transaction, tip);\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\r\n return await this.sendTransaction(signedTx);\r\n }\r\n\r\n private addTip(\r\n buyer: Keypair,\r\n transaction: Transaction,\r\n tip: number = 500000\r\n ): Transaction {\r\n if (tip <= 0) {\r\n return transaction;\r\n }\r\n const tipAccount = this.getRandomAccount();\r\n const tipInstructions = SystemProgram.transfer({\r\n fromPubkey: buyer.publicKey,\r\n toPubkey: tipAccount,\r\n lamports: tip,\r\n });\r\n transaction.add(tipInstructions);\r\n return transaction;\r\n }\r\n\r\n async ping() {\r\n return await AgentRegistry.callUpstream(\r\n \"astra\",\r\n `/iris?api-key=${this.key}`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"Content-Length\": Buffer.byteLength(getHealthBody),\r\n },\r\n body: getHealthBody,\r\n }\r\n );\r\n }\r\n\r\n async sendTransaction(vertionedTx: VersionedTransaction) {\r\n const serealized = vertionedTx.serialize();\r\n const tx = Buffer.from(serealized).toString(\"base64\");\r\n const UUID = crypto.randomUUID();\r\n const txbody = JSON.stringify({\r\n jsonrpc: \"2.0\",\r\n id: UUID,\r\n method: \"sendTransaction\",\r\n params: [tx, { encoding: \"base64\", skipPreflight: true, maxRetries: 0 }],\r\n });\r\n return await AgentRegistry.callUpstream(\r\n \"astra\",\r\n `/iris?api-key=${this.key}`,\r\n {\r\n method: \"POST\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"Content-Length\": Buffer.byteLength(txbody),\r\n },\r\n body: txbody,\r\n }\r\n );\r\n }\r\n}\r\n"],"names":["AgentRegistry","PublicKey","DEFAULT_COMMITMENT","calculateWithSlippageBuy","Transaction","buildSignedTx","calculateWithSlippageSell","SystemProgram","getHealthBody"],"mappings":";;;;;;;;MAkBa,WAAW,CAAA;AAEF,IAAA,GAAA;AADZ,IAAA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