-
Notifications
You must be signed in to change notification settings - Fork 6
/
status.ts
151 lines (129 loc) · 4.71 KB
/
status.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import {
LiquidityPoolKeysV4,
} from '@raydium-io/raydium-sdk'
import {
NATIVE_MINT,
} from '@solana/spl-token'
import {
Keypair,
Connection,
PublicKey,
LAMPORTS_PER_SOL,
} from '@solana/web3.js'
import {
BUY_LOWER_AMOUNT,
BUY_UPPER_AMOUNT,
CHECK_BAL_INTERVAL,
DISTRIBUTE_WALLET_NUM,
LOG_LEVEL,
PRIVATE_KEY,
RPC_ENDPOINT,
RPC_WEBSOCKET_ENDPOINT,
TOKEN_MINT,
} from './constants'
import { deleteConsoleLines, logger, PoolKeys, readJson, sleep } from './utils'
import base58 from 'bs58'
export const solanaConnection = new Connection(RPC_ENDPOINT, {
wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
})
export const mainKp = Keypair.fromSecretKey(base58.decode(PRIVATE_KEY))
const baseMint = new PublicKey(TOKEN_MINT)
const distritbutionNum = DISTRIBUTE_WALLET_NUM > 20 ? 20 : DISTRIBUTE_WALLET_NUM
let quoteVault: PublicKey | null = null
let poolKeys: LiquidityPoolKeysV4
let sold: number = 0
let bought: number = 0
let totalSolPut: number = 0
let changeAmount = 0
let buyNum = 0
let sellNum = 0
logger.level = LOG_LEVEL
interface Data {
privateKey: string;
pubkey: string;
solBalance: number | null;
tokenBuyTx: string | null,
tokenSellTx: string | null,
}
const data: Data[] = readJson()
const walletPks = data.map(data => data.pubkey)
console.log("🚀 ~ walletPks:", walletPks)
const main = async () => {
const solBalance = (await solanaConnection.getBalance(mainKp.publicKey)) / LAMPORTS_PER_SOL
console.log(`Wallet address: ${mainKp.publicKey.toBase58()}`)
console.log(`Pool token mint: ${baseMint.toBase58()}`)
console.log(`Wallet SOL balance: ${solBalance.toFixed(3)}SOL`)
console.log("Check interval: ", CHECK_BAL_INTERVAL, "ms")
let poolId: PublicKey
poolKeys = await PoolKeys.fetchPoolKeyInfo(solanaConnection, baseMint, NATIVE_MINT)
poolId = poolKeys.id
quoteVault = poolKeys.quoteVault
console.log(`Successfully fetched pool info`)
console.log(`Pool id: ${poolId.toBase58()}`)
trackWalletOnLog(solanaConnection, quoteVault)
}
const getPoolStatus = async (poolId: PublicKey) => {
while (true) {
try {
const res = await fetch(`https://api.dexscreener.com/latest/dex/pairs/solana/${poolId?.toBase58()}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
})
const data = await res.json()
const { url, priceNative, priceUsd, txns, volume, priceChange } = data.pair
// console.log(`\t url: ${url}`)
// console.log(`\t price: ${priceNative} SOL / ${priceUsd} usd`)
// console.log(`\t Volume status => m5: $${volume.m5}\t|\th1: $${volume.h1}\t|\th6: $${volume.h6}\t|\t h24: $${volume.h24}`)
// console.log(`\t Recent buy status (buy / sell) => m5: ${txns.m5.buys} / ${txns.m5.sells}\t\t|\th1: ${txns.h1.buys} / ${txns.h1.sells}\t|\th6: ${txns.h6.buys} / ${txns.h6.sells}\t|\t h24: ${txns.h24.buys} / ${txns.h24.sells}`)
// console.log(`\t volume price change => m5: ${priceChange.m5}%\t\t|\th1: ${priceChange.h1}%\t|\th6: ${priceChange.h6}%\t|\t h24: ${priceChange.h24}%`)
await sleep(5000)
} catch (error) {
console.log("Error fetching ")
await sleep(2000)
}
}
}
async function trackWalletOnLog(connection: Connection, quoteVault: PublicKey): Promise<void> {
const initialWsolBal = (await connection.getTokenAccountBalance(quoteVault)).value.uiAmount
if (!initialWsolBal) {
console.log("Quote vault mismatch")
return
}
const checkBal = setInterval(async () => {
const bal = (await connection.getTokenAccountBalance(quoteVault)).value.uiAmount
if (!bal) {
console.log("Quote vault mismatch")
return
}
changeAmount = bal - initialWsolBal
deleteConsoleLines(1)
console.log(`Other users bought ${buyNum - bought} times and sold ${sellNum - sold} times, total SOL change is ${changeAmount - totalSolPut}SOL`)
}, CHECK_BAL_INTERVAL)
try {
connection.onLogs(
quoteVault,
async ({ logs, err, signature }) => {
if (err) { }
else {
const parsedData = await connection.getParsedTransaction(signature, { maxSupportedTransactionVersion: 0, commitment: "confirmed" })
const signer = parsedData?.transaction.message.accountKeys.filter((elem: any) => {
return elem.signer == true
})[0].pubkey.toBase58()
// console.log(`\nTransaction success: https://solscan.io/tx/${signature}\n`)
if(!walletPks.includes(signer!)){
if (Number(parsedData?.meta?.preBalances[0]) > Number(parsedData?.meta?.postBalances[0])) {
buyNum++
} else {
sellNum++
}
}
}
},
"confirmed"
);
} catch (error) { }
}
main()