pump-trader 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -101,6 +101,7 @@ export declare class PumpTrader {
101
101
  getTradeMode(tokenAddr: string): Promise<"bonding" | "amm">;
102
102
  loadGlobal(): Promise<GlobalState>;
103
103
  getBondingPda(mint: PublicKey): PublicKey;
104
+ deriveBondingCurveV2(mint: PublicKey): PublicKey;
104
105
  loadBonding(mint: PublicKey): Promise<BondingInfo>;
105
106
  calcBuy(solIn: bigint, state: BondingCurveState): bigint;
106
107
  calcSell(tokenIn: bigint, state: BondingCurveState): bigint;
package/dist/index.js CHANGED
@@ -176,7 +176,15 @@ class PumpTrader {
176
176
  */
177
177
  async getTradeMode(tokenAddr) {
178
178
  const isAmmMode = await this.isAmmCompleted(tokenAddr);
179
- return isAmmMode ? "amm" : "bonding";
179
+ if (isAmmMode)
180
+ return "amm";
181
+ try {
182
+ await this.getAmmPoolInfo(new web3_js_1.PublicKey(tokenAddr));
183
+ return "amm";
184
+ }
185
+ catch {
186
+ return "bonding";
187
+ }
180
188
  }
181
189
  /* ---------- Global State ---------- */
182
190
  async loadGlobal() {
@@ -213,6 +221,9 @@ class PumpTrader {
213
221
  getBondingPda(mint) {
214
222
  return web3_js_1.PublicKey.findProgramAddressSync([SEEDS.BONDING, mint.toBuffer()], PROGRAM_IDS.PUMP)[0];
215
223
  }
224
+ deriveBondingCurveV2(mint) {
225
+ return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("bonding-curve-v2"), mint.toBuffer()], PROGRAM_IDS.PUMP)[0];
226
+ }
216
227
  async loadBonding(mint) {
217
228
  const bonding = this.getBondingPda(mint);
218
229
  const acc = await this.connection.getAccountInfo(bonding);
@@ -456,6 +467,7 @@ class PumpTrader {
456
467
  async buy(tokenAddr, totalSolIn, tradeOpt) {
457
468
  const mint = new web3_js_1.PublicKey(tokenAddr);
458
469
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
470
+ const bondingCurveV2 = this.deriveBondingCurveV2(mint);
459
471
  if (!this.globalState)
460
472
  await this.loadGlobal();
461
473
  const { bonding, state, creator } = await this.loadBonding(mint);
@@ -500,7 +512,8 @@ class PumpTrader {
500
512
  { pubkey: globalVolumeAccumulator, isSigner: false, isWritable: false },
501
513
  { pubkey: userVolumeAccumulator, isSigner: false, isWritable: true },
502
514
  { pubkey: feeConfig, isSigner: false, isWritable: false },
503
- { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
515
+ { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
516
+ { pubkey: bondingCurveV2, isSigner: false, isWritable: false }
504
517
  ],
505
518
  data: Buffer.concat([DISCRIMINATORS.BUY, u64(tokenOut), u64(maxSol)])
506
519
  }));
@@ -530,6 +543,7 @@ class PumpTrader {
530
543
  async sell(tokenAddr, totalTokenIn, tradeOpt) {
531
544
  const mint = new web3_js_1.PublicKey(tokenAddr);
532
545
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
546
+ const bondingCurveV2 = this.deriveBondingCurveV2(mint);
533
547
  if (!this.globalState)
534
548
  await this.loadGlobal();
535
549
  const { bonding, state, creator } = await this.loadBonding(mint);
@@ -573,7 +587,8 @@ class PumpTrader {
573
587
  { pubkey: PROGRAM_IDS.EVENT_AUTHORITY, isSigner: false, isWritable: false },
574
588
  { pubkey: PROGRAM_IDS.PUMP, isSigner: false, isWritable: false },
575
589
  { pubkey: feeConfig, isSigner: false, isWritable: false },
576
- { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
590
+ { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
591
+ { pubkey: bondingCurveV2, isSigner: false, isWritable: false }
577
592
  ],
578
593
  data: Buffer.concat([
579
594
  DISCRIMINATORS.SELL,
package/index.js CHANGED
@@ -230,7 +230,13 @@ export class PumpTrader {
230
230
  */
231
231
  async getTradeMode(tokenAddr) {
232
232
  const isAmmMode = await this.isAmmCompleted(tokenAddr);
233
- return isAmmMode ? "amm" : "bonding";
233
+ if (isAmmMode) return "amm";
234
+ try {
235
+ await this.getAmmPoolInfo(new PublicKey(tokenAddr));
236
+ return "amm";
237
+ } catch {
238
+ return "bonding";
239
+ }
234
240
  }
235
241
 
236
242
  /* ---------- Global State ---------- */
@@ -278,6 +284,13 @@ export class PumpTrader {
278
284
  )[0];
279
285
  }
280
286
 
287
+ deriveBondingCurveV2(mint) {
288
+ return PublicKey.findProgramAddressSync(
289
+ [Buffer.from("bonding-curve-v2"), mint.toBuffer()],
290
+ PROGRAM_IDS.PUMP
291
+ )[0];
292
+ }
293
+
281
294
  async loadBonding(mint) {
282
295
  const bonding = this.getBondingPda(mint);
283
296
  const acc = await this.connection.getAccountInfo(bonding);
@@ -611,6 +624,7 @@ export class PumpTrader {
611
624
  async buy(tokenAddr, totalSolIn, tradeOpt) {
612
625
  const mint = new PublicKey(tokenAddr);
613
626
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
627
+ const bondingCurveV2 = this.deriveBondingCurveV2(mint);
614
628
 
615
629
  if (!this.globalState) await this.loadGlobal();
616
630
 
@@ -685,7 +699,8 @@ export class PumpTrader {
685
699
  { pubkey: globalVolumeAccumulator, isSigner: false, isWritable: false },
686
700
  { pubkey: userVolumeAccumulator, isSigner: false, isWritable: true },
687
701
  { pubkey: feeConfig, isSigner: false, isWritable: false },
688
- { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
702
+ { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
703
+ { pubkey: bondingCurveV2, isSigner: false, isWritable: false }
689
704
  ],
690
705
  data: Buffer.concat([DISCRIMINATORS.BUY, u64(tokenOut), u64(maxSol)])
691
706
  })
@@ -721,6 +736,7 @@ export class PumpTrader {
721
736
  async sell(tokenAddr, totalTokenIn, tradeOpt) {
722
737
  const mint = new PublicKey(tokenAddr);
723
738
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
739
+ const bondingCurveV2 = this.deriveBondingCurveV2(mint);
724
740
 
725
741
  if (!this.globalState) await this.loadGlobal();
726
742
 
@@ -798,7 +814,8 @@ export class PumpTrader {
798
814
  { pubkey: PROGRAM_IDS.EVENT_AUTHORITY, isSigner: false, isWritable: false },
799
815
  { pubkey: PROGRAM_IDS.PUMP, isSigner: false, isWritable: false },
800
816
  { pubkey: feeConfig, isSigner: false, isWritable: false },
801
- { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
817
+ { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
818
+ { pubkey: bondingCurveV2, isSigner: false, isWritable: false }
802
819
  ],
803
820
  data: Buffer.concat([
804
821
  DISCRIMINATORS.SELL,
package/index.ts CHANGED
@@ -328,7 +328,13 @@ export class PumpTrader {
328
328
  */
329
329
  async getTradeMode(tokenAddr: string): Promise<"bonding" | "amm"> {
330
330
  const isAmmMode = await this.isAmmCompleted(tokenAddr);
331
- return isAmmMode ? "amm" : "bonding";
331
+ if (isAmmMode) return "amm";
332
+ try {
333
+ await this.getAmmPoolInfo(new PublicKey(tokenAddr));
334
+ return "amm";
335
+ } catch {
336
+ return "bonding";
337
+ }
332
338
  }
333
339
 
334
340
  /* ---------- Global State ---------- */
@@ -376,6 +382,13 @@ export class PumpTrader {
376
382
  )[0];
377
383
  }
378
384
 
385
+ deriveBondingCurveV2(mint: PublicKey): PublicKey {
386
+ return PublicKey.findProgramAddressSync(
387
+ [Buffer.from("bonding-curve-v2"), mint.toBuffer()],
388
+ PROGRAM_IDS.PUMP
389
+ )[0];
390
+ }
391
+
379
392
  async loadBonding(mint: PublicKey): Promise<BondingInfo> {
380
393
  const bonding = this.getBondingPda(mint);
381
394
  const acc = await this.connection.getAccountInfo(bonding);
@@ -716,6 +729,7 @@ export class PumpTrader {
716
729
  async buy(tokenAddr: string, totalSolIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult> {
717
730
  const mint = new PublicKey(tokenAddr);
718
731
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
732
+ const bondingCurveV2 = this.deriveBondingCurveV2(mint);
719
733
 
720
734
  if (!this.globalState) await this.loadGlobal();
721
735
 
@@ -792,7 +806,8 @@ export class PumpTrader {
792
806
  { pubkey: globalVolumeAccumulator, isSigner: false, isWritable: false },
793
807
  { pubkey: userVolumeAccumulator, isSigner: false, isWritable: true },
794
808
  { pubkey: feeConfig, isSigner: false, isWritable: false },
795
- { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
809
+ { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
810
+ { pubkey: bondingCurveV2, isSigner: false, isWritable: false }
796
811
  ],
797
812
  data: Buffer.concat([DISCRIMINATORS.BUY, u64(tokenOut), u64(maxSol)])
798
813
  })
@@ -828,6 +843,7 @@ export class PumpTrader {
828
843
  async sell(tokenAddr: string, totalTokenIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult> {
829
844
  const mint = new PublicKey(tokenAddr);
830
845
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
846
+ const bondingCurveV2 = this.deriveBondingCurveV2(mint);
831
847
 
832
848
  if (!this.globalState) await this.loadGlobal();
833
849
 
@@ -905,7 +921,8 @@ export class PumpTrader {
905
921
  { pubkey: PROGRAM_IDS.EVENT_AUTHORITY, isSigner: false, isWritable: false },
906
922
  { pubkey: PROGRAM_IDS.PUMP, isSigner: false, isWritable: false },
907
923
  { pubkey: feeConfig, isSigner: false, isWritable: false },
908
- { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false }
924
+ { pubkey: PROGRAM_IDS.FEE, isSigner: false, isWritable: false },
925
+ { pubkey: bondingCurveV2, isSigner: false, isWritable: false }
909
926
  ],
910
927
  data: Buffer.concat([
911
928
  DISCRIMINATORS.SELL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pump-trader",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "PumpFun 交易库 - 自动判断 Token Program 和内盘/外盘",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",