Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Abegg committed Jun 19, 2024
1 parent 854f52e commit 3a7a3f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/new.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@degenfrends/solana-pumpfun-trader': patch
---

## @degenfrends/solana-pumpfun-trader: Discord fixes
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ export default class PumpFunTrader {
) {
try {
const txBuilder = new Transaction();

const instruction = await this.getBuyInstruction(privateKey, tokenAddress, amount, slippage, txBuilder);
if (!instruction?.instruction) {
this.logger.error('Failed to retrieve buy instruction...');
return;
}
txBuilder.add(instruction.instruction);
await this.createAndSendTransaction(txBuilder, privateKey, priorityFee, isSimulation);
const signature = await this.createAndSendTransaction(txBuilder, privateKey, priorityFee, isSimulation);
this.logger.log('Sell transaction confirmed:', signature);

return signature;
} catch (error) {
this.logger.log(error);
}
Expand All @@ -67,7 +69,7 @@ export default class PumpFunTrader {
isSimulation: boolean = true
) {
try {
const instruction = await this.getSellInstruction(privateKey, tokenAddress, tokenBalance, priorityFee, slippage);
const instruction = await this.getSellInstruction(privateKey, tokenAddress, tokenBalance, slippage);
const txBuilder = new Transaction();
if (!instruction) {
this.logger.error('Failed to retrieve sell instruction...');
Expand All @@ -76,9 +78,8 @@ export default class PumpFunTrader {

txBuilder.add(instruction);

const payer = await getKeyPairFromPrivateKey(privateKey);

await this.createAndSendTransaction(txBuilder, privateKey, priorityFee, isSimulation);
const signature = await this.createAndSendTransaction(txBuilder, privateKey, priorityFee, isSimulation);
this.logger.log('Sell transaction confirmed:', signature);
} catch (error) {
this.logger.log(error);
}
Expand All @@ -89,6 +90,7 @@ export default class PumpFunTrader {
if (isSimulation == false) {
const signature = await sendTransaction(this.connection, transaction, [walletPrivateKey]);
this.logger.log('Buy transaction confirmed:', signature);
return signature;
} else if (isSimulation == true) {
const simulatedResult = await this.connection.simulateTransaction(transaction);
this.logger.log(simulatedResult);
Expand Down Expand Up @@ -153,7 +155,7 @@ export default class PumpFunTrader {

return { instruction: instruction, tokenAmount: tokenOut };
}
async getSellInstruction(privateKey: string, tokenAddress: string, tokenBalance: number, priorityFee: number = 0, slippage: number = 0.25) {
async getSellInstruction(privateKey: string, tokenAddress: string, tokenBalance: number, slippage: number = 0.25) {
const coinData = await getCoinData(tokenAddress);
if (!coinData) {
this.logger.error('Failed to retrieve coin data...');
Expand Down

0 comments on commit 3a7a3f0

Please sign in to comment.