pump-trader 1.0.3 → 1.0.4
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 +5 -3
- package/index.js +6 -4
- package/index.ts +5 -3
- package/package.json +1 -1
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
|
|
617
|
-
const
|
|
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);
|
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
|
|
849
|
-
const
|
|
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(
|
|
@@ -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
|
|
956
|
-
const
|
|
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(
|