{"version":3,"file":"NodeOneModule.cjs","sources":["../../../../src/modules/NodeOneModule.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 NodeOneModule {\r\n  private key: string;\r\n  constructor(private sdk: PumpFunSDK, region: Region, key: string) {\r\n    AgentRegistry.registerInConfig(\"node\", region);\r\n    this.key = key;\r\n  }\r\n\r\n  NODE_ONE_ACCOUNTS = [\r\n    new PublicKey(\"node1PqAa3BWWzUnTHVbw8NJHC874zn9ngAkXjgWEej\"),\r\n    new PublicKey(\"node1UzzTxAAeBTpfZkQPJXBAqixsbdth11ba1NXLBG\"),\r\n    new PublicKey(\"node1Qm1bV4fwYnCurP8otJ9s5yrkPq7SPZ5uhj3Tsv\"),\r\n    new PublicKey(\"node1PUber6SFmSQgvf2ECmXsHP5o3boRSGhvJyPMX1\"),\r\n    new PublicKey(\"node1AyMbeqiVN6eoQzEAwCA6Pk826hrdqdAHR7cdJ3\"),\r\n    new PublicKey(\"node1YtWCoTwwVYTFLfS19zquRQzYX332hs1HEuRBjC\"),\r\n    new PublicKey(\"node1FdMPnJBN7QTuhzNw3VS823nxFuDTizrrbcEqzp\"),\r\n  ];\r\n\r\n  private getRandomAccount() {\r\n    const randomIndex = Math.floor(\r\n      Math.random() * this.NODE_ONE_ACCOUNTS.length\r\n    );\r\n    return this.NODE_ONE_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(\"node\", \"/ping\", {\r\n      method: \"GET\",\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(\"node\", `/`, {\r\n      method: \"POST\",\r\n      headers: {\r\n        \"Content-Type\": \"application/json\",\r\n        \"Content-Length\": Buffer.byteLength(txbody),\r\n        \"api-key\": this.key,\r\n      },\r\n      body: txbody,\r\n    });\r\n  }\r\n}\r\n"],"names":["AgentRegistry","PublicKey","DEF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