pump-trader 1.0.3 → 1.0.5

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.js CHANGED
@@ -605,7 +605,6 @@ class PumpTrader {
605
605
  async ammBuy(tokenAddr, totalSolIn, tradeOpt) {
606
606
  const mint = new web3_js_1.PublicKey(tokenAddr);
607
607
  const poolInfo = await this.getAmmPoolInfo(mint);
608
- const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
609
608
  const solChunks = this.splitByMax(totalSolIn, tradeOpt.maxSolPerTx);
610
609
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
611
610
  const pendingTransactions = [];
@@ -613,13 +612,16 @@ class PumpTrader {
613
612
  for (let i = 0; i < solChunks.length; i++) {
614
613
  try {
615
614
  const solIn = solChunks[i];
616
- const baseAmountOut = this.calculateAmmBuyOutput(solIn, reserves);
617
- const slippageBps = this.calcSlippage({
615
+ const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
616
+ const rawSlippageBps = this.calcSlippage({
618
617
  tradeSize: solIn,
619
618
  reserve: reserves.quoteAmount,
620
619
  slippageOpt: tradeOpt.slippage
621
620
  });
621
+ const slippageBps = Math.max(0, Math.min(rawSlippageBps, 9000));
622
622
  const maxQuoteIn = (solIn * BigInt(10_000 + slippageBps)) / 10000n;
623
+ const estimatedBaseOut = this.calculateAmmBuyOutput(solIn, reserves);
624
+ const baseAmountOut = ((estimatedBaseOut * BigInt(10_000 - slippageBps)) / 10000n) || 1n;
623
625
  const priority = this.genPriority(tradeOpt.priority);
624
626
  const tx = new web3_js_1.Transaction().add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 300_000 }), web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priority }));
625
627
  const userBaseAta = await this.ensureAta(tx, poolInfo.poolKeys.baseMint, tokenProgram.programId);
@@ -790,7 +792,8 @@ class PumpTrader {
790
792
  DISCRIMINATORS.BUY,
791
793
  u64(baseAmountOut),
792
794
  u64(maxQuoteAmountIn),
793
- Buffer.from([1, 1])
795
+ // trackVolume = Some(false) to avoid recent overflow path in pump-amm buy accounting
796
+ Buffer.from([1, 0])
794
797
  ])
795
798
  });
796
799
  }
package/index.js CHANGED
@@ -836,7 +836,6 @@ export class PumpTrader {
836
836
  async ammBuy(tokenAddr, totalSolIn, tradeOpt) {
837
837
  const mint = new PublicKey(tokenAddr);
838
838
  const poolInfo = await this.getAmmPoolInfo(mint);
839
- const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
840
839
  const solChunks = this.splitByMax(totalSolIn, tradeOpt.maxSolPerTx);
841
840
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
842
841
  const pendingTransactions = [];
@@ -845,13 +844,16 @@ export class PumpTrader {
845
844
  for (let i = 0; i < solChunks.length; i++) {
846
845
  try {
847
846
  const solIn = solChunks[i];
848
- const baseAmountOut = this.calculateAmmBuyOutput(solIn, reserves);
849
- const slippageBps = this.calcSlippage({
847
+ const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
848
+ const rawSlippageBps = this.calcSlippage({
850
849
  tradeSize: solIn,
851
850
  reserve: reserves.quoteAmount,
852
851
  slippageOpt: tradeOpt.slippage
853
852
  });
853
+ const slippageBps = Math.max(0, Math.min(rawSlippageBps, 9000));
854
854
  const maxQuoteIn = (solIn * BigInt(10_000 + slippageBps)) / 10_000n;
855
+ const estimatedBaseOut = this.calculateAmmBuyOutput(solIn, reserves);
856
+ const baseAmountOut = ((estimatedBaseOut * BigInt(10_000 - slippageBps)) / 10_000n) || 1n;
855
857
  const priority = this.genPriority(tradeOpt.priority);
856
858
 
857
859
  const tx = new Transaction().add(
@@ -1142,7 +1144,7 @@ export class PumpTrader {
1142
1144
  DISCRIMINATORS.BUY,
1143
1145
  u64(baseAmountOut),
1144
1146
  u64(maxQuoteAmountIn),
1145
- Buffer.from([1, 1]) // trackVolume = Some(true)
1147
+ Buffer.from([1, 0]) // trackVolume = Some(false)
1146
1148
  ])
1147
1149
  });
1148
1150
  }
@@ -1373,4 +1375,4 @@ export class PumpTrader {
1373
1375
  getCachedTokenProgram(tokenAddr) {
1374
1376
  return this.tokenProgramCache.get(tokenAddr);
1375
1377
  }
1376
- }
1378
+ }
package/index.ts CHANGED
@@ -943,7 +943,6 @@ export class PumpTrader {
943
943
  async ammBuy(tokenAddr: string, totalSolIn: bigint, tradeOpt: TradeOptions): Promise<TradeResult> {
944
944
  const mint = new PublicKey(tokenAddr);
945
945
  const poolInfo = await this.getAmmPoolInfo(mint);
946
- const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
947
946
  const solChunks = this.splitByMax(totalSolIn, tradeOpt.maxSolPerTx);
948
947
  const tokenProgram = await this.detectTokenProgram(tokenAddr);
949
948
  const pendingTransactions: PendingTransaction[] = [];
@@ -952,13 +951,16 @@ export class PumpTrader {
952
951
  for (let i = 0; i < solChunks.length; i++) {
953
952
  try {
954
953
  const solIn = solChunks[i];
955
- const baseAmountOut = this.calculateAmmBuyOutput(solIn, reserves);
956
- const slippageBps = this.calcSlippage({
954
+ const reserves = await this.getAmmPoolReserves(poolInfo.poolKeys);
955
+ const rawSlippageBps = this.calcSlippage({
957
956
  tradeSize: solIn,
958
957
  reserve: reserves.quoteAmount,
959
958
  slippageOpt: tradeOpt.slippage
960
959
  });
960
+ const slippageBps = Math.max(0, Math.min(rawSlippageBps, 9000));
961
961
  const maxQuoteIn = (solIn * BigInt(10_000 + slippageBps)) / 10_000n;
962
+ const estimatedBaseOut = this.calculateAmmBuyOutput(solIn, reserves);
963
+ const baseAmountOut = ((estimatedBaseOut * BigInt(10_000 - slippageBps)) / 10_000n) || 1n;
962
964
  const priority = this.genPriority(tradeOpt.priority);
963
965
 
964
966
  const tx = new Transaction().add(
@@ -1255,7 +1257,8 @@ export class PumpTrader {
1255
1257
  DISCRIMINATORS.BUY,
1256
1258
  u64(baseAmountOut),
1257
1259
  u64(maxQuoteAmountIn),
1258
- Buffer.from([1, 1])
1260
+ // trackVolume = Some(false) to avoid recent overflow path in pump-amm buy accounting
1261
+ Buffer.from([1, 0])
1259
1262
  ])
1260
1263
  });
1261
1264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pump-trader",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "PumpFun 交易库 - 自动判断 Token Program 和内盘/外盘",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",