From 2f0e73c9eb7370501dc4bd0b201a735652dd9896 Mon Sep 17 00:00:00 2001 From: OneRobotBoii Date: Sun, 18 Feb 2024 18:51:11 +0700 Subject: [PATCH] Remove pnpm Remove work script command Reuse poolkeys for sell --- .gitignore | 6 +++++- buy.ts | 20 ++++++-------------- package.json | 3 +-- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 1959e3c..b21b29c 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,8 @@ dist .pnp.* -.idea \ No newline at end of file +.idea +TODO + +# pnpm +pnpm-lock.yaml \ No newline at end of file diff --git a/buy.ts b/buy.ts index 823d4dd..480448a 100644 --- a/buy.ts +++ b/buy.ts @@ -210,7 +210,8 @@ export async function processRaydiumPool( const timeout = parseInt(SELL_DELAY, 10); await new Promise((resolve) => setTimeout(resolve, timeout)); - await sell(id, poolState); + let poolKeys = existingTokenAccounts.get(poolState.baseMint.toString())!.poolKeys; + await sell(id, poolState, poolKeys as LiquidityPoolKeys); } } catch (e) { logger.error({ ...poolState, error: e }, `Failed to process pool`); @@ -312,6 +313,7 @@ const maxRetries = 60; async function sell( accountId: PublicKey, accountData: LiquidityStateV4, + poolKeys: LiquidityPoolKeys, ): Promise { const tokenAccount = existingTokenAccounts.get( accountData.baseMint.toString(), @@ -328,14 +330,9 @@ async function sell( if (balanceResponse !== null && Number(balanceResponse) > 0 && !balanceFound) { balanceFound = true; - tokenAccount.poolKeys = createPoolKeys( - accountId, - accountData, - tokenAccount.market!, - ); const { innerTransaction, address } = Liquidity.makeSwapFixedInInstruction( { - poolKeys: tokenAccount.poolKeys, + poolKeys: poolKeys, userKeys: { tokenAccountIn: tokenAccount.address, tokenAccountOut: quoteTokenAssociatedAddress, @@ -344,7 +341,7 @@ async function sell( amountIn: new BN(balanceResponse), minAmountOut: 0, }, - tokenAccount.poolKeys.version, + poolKeys.version, ); const latestBlockhash = await solanaConnection.getLatestBlockhash({ @@ -356,12 +353,6 @@ async function sell( instructions: [ ComputeBudgetProgram.setComputeUnitLimit({ units: 400000 }), ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 200000 }), - createAssociatedTokenAccountIdempotentInstruction( - wallet.publicKey, - tokenAccount.address, - wallet.publicKey, - accountData.baseMint, - ), ...innerTransaction.instructions, ], }).compileToV0Message(); @@ -384,6 +375,7 @@ async function sell( break; } } catch (error) { + // logger.error(`Error while selling: ${error}`); } retries++; await new Promise((resolve) => setTimeout(resolve, 1000)); diff --git a/package.json b/package.json index 29988dc..18af0e5 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,7 @@ "name": "solana-sniper-bot", "author": "Filip Dundjer", "scripts": { - "buy": "ts-node buy.ts", - "work": "ts-node worker/watcher.ts" + "buy": "ts-node buy.ts" }, "dependencies": { "@raydium-io/raydium-sdk": "^1.3.1-beta.47",