Skip to content

Commit

Permalink
snipe guaranteed 😏
Browse files Browse the repository at this point in the history
  • Loading branch information
edceds committed Nov 15, 2024
1 parent 2c58b23 commit d1020ed
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 66 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules/
.env
test.ts
payer.json
payer.json
wallets/
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ const getSnipeTransaction = async (
tokenMint,
tokenPairAddress,
amountToBuyInSol,
0.0005,
tokenRaydiumPoolKeys
)

Expand All @@ -384,8 +385,6 @@ const getSnipeTransaction = async (
keypair,
new PublicKey(tokenMint),
new PublicKey(tokenPairAddress),
new PublicKey(tokenPumpfunBondingCurveAta!),
new PublicKey(tokenPumpfunGlobalAddress!),
amountToBuyInSol
)

Expand Down
10 changes: 5 additions & 5 deletions src/lib/jito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const connection = new Connection(heliusRpcUrl)
const payerKeypair = Keypair.fromSecretKey(
Uint8Array.from(JSON.parse(process.env.JITO_PAYER_KEYPAIR as string))
)
export async function sendJitoBundle(transactions: Uint8Array[], jitoTipAmountInSol = 0.0029) {
export async function sendJitoBundle(transactions: Uint8Array[], jitoTipAmountInSol = 0.00029) {
const base58EncodedTransactions = transactions.map((tx) => bs58.encode(tx))
const jitoClient = new JitoJsonRpcClient(
"https://mainnet.block-engine.jito.wtf/api/v1",
Expand Down Expand Up @@ -102,10 +102,10 @@ export async function sendJitoBundle(transactions: Uint8Array[], jitoTipAmountIn
// }

} catch (e: any) {
console.error("Error sending batch:", e)
if (e.response && e.response.data) {
console.error("Server response:", e.response.data)
}
// console.error("Error sending batch:", e)
// if (e.response && e.response.data) {
// console.error("Server response:", e.response.data)
// }

}

Expand Down
25 changes: 22 additions & 3 deletions src/lib/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@ import postgres from "postgres"
import { DigitalAsset } from "@metaplex-foundation/mpl-token-metadata"
import dotenv from "dotenv"

dotenv.config({
path: '/root/workspace/moonbot/.env'
})
dotenv.config()

export const sql = postgres(process.env.DATABASE_URL as string)

export const getCoinsPairs = async (mints: string[]) => {
const results = await sql<
{ pair: string, mint: string, source: string }[]>`
select pair, mint, source from coins where mint IN ${sql(mints)}
`

const pairByMint: Record<string, { pair: string, mint: string, source: string }> = {}
if (results.length) {
for (const result of results) {
const { pair, mint, source } = result
pairByMint[mint] = {
pair, source, mint
}
}

}

return pairByMint
}


export type PairSqlRow = {
token_mint: string
address: string
Expand Down
26 changes: 18 additions & 8 deletions src/lib/pumpfun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
createAssociatedTokenAccountInstruction,
getAssociatedTokenAddressSync,
} from "@solana/spl-token"
import { MEMO_PROGRAM_ID } from "@raydium-io/raydium-sdk"
import { ASSOCIATED_TOKEN_PROGRAM_ID, MEMO_PROGRAM_ID } from "@raydium-io/raydium-sdk"
import chalk from "chalk"

const connection = new Connection(heliusRpcUrl, {
Expand All @@ -40,8 +40,6 @@ const program = new Program(
const feeRecipient = "CebN5WGQ4jvEPvsVU4EoHEpgzq1VV7AbicfhtW4xC9iM"
const EVENT_AUTH = "Ce6TQqeHC9p8KetsN6JsjHK7UTZk7nasjjnr7XxXp9F1"

const priorityFee = 0.000011 * LAMPORTS_PER_SOL

const globalState = new PublicKey(
"4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf"
)
Expand All @@ -50,17 +48,27 @@ const jitoPayerKeypair = Keypair.fromSecretKey(
Uint8Array.from(JSON.parse(process.env.JITO_PAYER_KEYPAIR as string))
)


export const getBuyPumpfunTokenTransaction = async (
connection: Connection,
keypair: Keypair,
tokenMint: PublicKey,
bondingCurve: PublicKey,
bondingCurveAta: PublicKey,
globalState: PublicKey,
amountInSol = 0.003
amountInSol = 0.003,
feesInSol = 0.000011
) => {
let bought = false
let tries = 1
const priorityFee = feesInSol * LAMPORTS_PER_SOL

const [associatedBondingCurve] = PublicKey.findProgramAddressSync(
[
bondingCurve.toBuffer(),
TOKEN_PROGRAM_ID.toBuffer(),
tokenMint.toBuffer(),
],
ASSOCIATED_TOKEN_PROGRAM_ID
)

while (!bought && tries < 5) {
try {
Expand Down Expand Up @@ -119,7 +127,7 @@ export const getBuyPumpfunTokenTransaction = async (
feeRecipient: feeRecipient,
mint: tokenMint,
bondingCurve: bondingCurve,
associatedBondingCurve: bondingCurveAta,
associatedBondingCurve,
associatedUser: userAta,
user: user,
systemProgram: SystemProgram.programId,
Expand Down Expand Up @@ -221,9 +229,11 @@ export const getSellPumpfunTokenTransaction = async (
bondingCurve: PublicKey,
bondingCurveAta: PublicKey,
globalState: PublicKey,
amount: number
amount: number,
feesInSol = 0.000011
) => {
let tries = 1
const priorityFee = feesInSol * LAMPORTS_PER_SOL

while (tries <= 5) {
try {
Expand Down
21 changes: 3 additions & 18 deletions src/lib/raydium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,13 @@ export const getBuyRaydiumTokenTransaction = async (
tokenMint: string,
poolId: string,
amountInSol: number = 0.01,
feesInSol = 0.0001,
poolKeys?: Awaited<ReturnType<typeof fetchPoolAndMarketAccounts>>["poolKeys"]
) => {
let tries = 1

while (tries < 5) {
try {
const balance = await getWalletTokenBalance(
connection,
keypair.publicKey,
new PublicKey(tokenMint)
)

if (balance?.value.uiAmount) {
console.log(`Wallet ${keypair.publicKey.toString()} already has balance for ${tokenMint}`)
break
}

if (!poolKeys) {
try {
poolKeys = (await fetchPoolAndMarketAccounts(connection, poolId))
Expand All @@ -64,19 +54,14 @@ export const getBuyRaydiumTokenTransaction = async (
}
}

console.log(
`${chalk.green(
"[SNIPING_BOT]"
)} Attempt ${tries} to buy ${tokenMint} for ${keypair.publicKey.toString()} | ${new Date().toUTCString()}`
)

const ixsRes = await getSwapInstructions(
connection,
keypair,
poolKeys,
"buy",
amountInSol,
51
51,
feesInSol
)

if (!ixsRes) {
Expand Down
Loading

0 comments on commit d1020ed

Please sign in to comment.