-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.ts
445 lines (375 loc) · 13.2 KB
/
index.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import { id } from 'ethers';
import {Telegraf, TelegramError} from 'telegraf'
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
import { gql, GraphQLClient } from "graphql-request";
import * as anchor from "@project-serum/anchor";
import {Buy,Sell} from "./swapAmm"
import {
Metadata,
PROGRAM_ID as TOKEN_METADATA_PROGRAM_ID,
} from "@metaplex-foundation/mpl-token-metadata";
import { Wallet } from '@project-serum/anchor';
import { quote } from 'telegraf/typings/format';
//const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
const { getOrCreateAssociatedTokenAccount } = require('@solana/spl-token');
const privateKey = new Uint8Array([
//add your private key
]);
const wallet = new Wallet(Keypair.fromSecretKey(privateKey));
const api =" " //add your api;
const SESSION_HASH = 'QNDEMO' + Math.ceil(Math.random() * 1e9); // Random unique identifier for your session
const endpoint = `https://programs.shyft.to/v0/graphql/?api_key=${api}`;
// const connection = new Connection(`https://solana-mainnet.core.chainstack.com/500a50e949070da73951d8d4f493532b`, {
// wsEndpoint: `wss://solana-mainnet.core.chainstack.com/ws/500a50e949070da73951d8d4f493532b`,
// httpHeaders: {"x-session-hash": SESSION_HASH}
// });
const connection = new Connection(`https://rpc.shyft.to?api_key= your api key`, 'confirmed');
//`https://solana-mainnet.core.chainstack.com/968251fbfe51d98ea3cee0bf693ba515`
//wss://solana-mainnet.core.chainstack.com/ws/968251fbfe51d98ea3cee0bf693ba515`
const graphQLClient = new GraphQLClient(endpoint, {
method: `POST`,
jsonSerializer: {
parse: JSON.parse,
stringify: JSON.stringify,
},
});
const TELEGRAM_BOT_TOKEN = "Your Token"
const bot = new Telegraf(TELEGRAM_BOT_TOKEN)
const msgId = 'input your chat id';
var myHeaders = new Headers();
let token;
let pair;
let decimal;
let confirm;
const amount = 1000000 // input any amount of your choice
var trades : Array<String> = []
//bot.use(Telegraf.log())
bot.command('enterTrade', async (ctx) => await ctx.reply('Hi, Ready to enter Trade, Please give the command ', {
reply_markup : {
inline_keyboard : [
[
{
text : "setUp",
callback_data : "SetUp"
},
{
text : "Clear",
callback_data: "Delete"
},
{
text : "Fetch",
callback_data: "get"
}
]
]
}
}));
bot.command('sell', async(ctx) => {
console.log(`Token ${token}, Pair ${pair}, Decimal ${decimal}`)
orderSell(token,pair,Number(decimal));
// if(successful == true){
// ctx.reply("Sell Successful");
// }
})
bot.action(/.+/,async (ctx) => {
if(ctx.match[0] == "SetUp"){
ctx.reply("Enter token contract address");
}else if(ctx.match[0] == "Delete"){
ctx.reply("Deleting All Entry")
trades = []
}else if(ctx.match[0] == "get"){
if(trades.length == 0){
ctx.reply("Entry is Empty");
}else{
ctx.reply("Fetching all Locked in Tokens and Details");
ctx.reply(`${trades.join(", ")}`)
}
}
})
bot.on('text', async(ctx) => {
const Response = ctx.message?.text!
if(trades.length >= 3){
ctx.reply("Entry Filled");
}else{
console.log(Response)
ctx.reply(`Locking in Token Address : ${Response}`)
trades.push(Response);
// ctx.deleteMessage();
if(trades.length>=1){
let tokenInfo = await info(Response);
let tInfo;
if(tokenInfo == null){
tInfo = true;
}
if(
tInfo == true
){
ctx.reply("Token is yet to Launch");
if(Response == trades[0]){
ctx.reply(`${trades[0]} Without Lp
Saving Contract till LP
`)
console.log("trade : " + trades[0])
let interval = setInterval(async() => {
tokenInfo = await info(trades[0])
console.log(`Searching for ${trades[0]}`)
if(tokenInfo != null){
console.log(`Search over`);
tInfo = false;
clearInterval(interval)
console.log(`${tokenInfo.tokenName} Launched!!`)
ctx.reply(
` 🪙 ${tokenInfo.tokenName} Token Info
Name: ${tokenInfo.tokenName}
Symbol: ${tokenInfo.tokenSym}
Pair Token : SOLANA
Pair: ${tokenInfo.lp}
Token: ${tokenInfo.token}
Vault: ${tokenInfo.vault}
Sol Bal: ${Number(tokenInfo.vaultBalance).toFixed(2)} Sol
Decimal: ${tokenInfo.decimal}
OpenTime: ${tokenInfo.startTime}
👨🏻💻 Owner Info
Address: ${tokenInfo.owner}
Balance: ${Number(tokenInfo.ownerBalance).toFixed(2)} SOL
`
)
token = tokenInfo.token
pair = tokenInfo.lp;
decimal = tokenInfo.decimal;
const now : any = new Date();
const targetTime : any = new Date(tokenInfo.startTime.getFullYear(), tokenInfo.startTime.getMonth(),tokenInfo.startTime.getDate(), tokenInfo.startTime.getHours(), tokenInfo.startTime.getMinutes(), tokenInfo.startTime.getSeconds(),tokenInfo.startTime.getMilliseconds());
const timeDiff : any = targetTime - now;
const msUntilTarget = timeDiff > 0 ? timeDiff : 86400000 - Math.abs(timeDiff);
await orderBuys(tokenInfo.token.toString(),tokenInfo.lp.toString(),Number(tokenInfo.decimal))
const MAX_RETRIES = 10000;
const BASE_DELAY = 1000;
let retries = 0;
let delay = BASE_DELAY;
const Addr = new PublicKey(tokenInfo.vault)
let profit : Number;
const subscriptionID = connection.onAccountChange(
Addr,
async(updatedAccountInfo, context) => {
const Bal= updatedAccountInfo.lamports/1000000000
const prof = Number(Bal) / Number(tokenInfo?.vaultBalance);
console.log(prof);
while (retries < MAX_RETRIES) {
try {
await ctx.reply(
`
${tokenInfo.tokenSym} : ${tokenInfo.token}
SOL : So11111111111111111111111111111111111111112
${Number(tokenInfo.vaultBalance).toFixed(2)} SOL
Profit : ${Number(prof).toFixed(2)}x
`
)
return;
} catch (error) {
if (error.response && error.response.error_code === 429) {
console.log(`Profit on console.. TG in ${delay}ms...`);
await new Promise(resolve => setTimeout(resolve, delay));
retries++;
delay *= 1.5; // double the delay for each retry
if (delay > 60000) { // limit the maximum delay to 60 seconds
delay = 60000;
}
} else {
throw error;
}
}
}
throw new Error('Max retries exceeded');
}
)
}
}, 10000)
}
}else{
ctx.reply(
` 🪙 ${tokenInfo.tokenName} Token Info
Name: ${tokenInfo.tokenName}
Symbol: ${tokenInfo.tokenSym}
Pair Token : SOLANA
Pair: ${tokenInfo.lp}
Token: ${tokenInfo.token}
Vault: ${tokenInfo.vault}
Sol Bal: ${Number(tokenInfo.vaultBalance).toFixed(2)} Sol
Decimal: ${tokenInfo.decimal}
OpenTime: ${tokenInfo.startTime}
👨🏻💻 Owner Info
Address: ${tokenInfo.owner}
Balance: ${Number(tokenInfo.ownerBalance).toFixed(2)} SOL
`
)
// if(tokenInfo.successful == true){
// ctx.reply(`Buy Successful`);
// }
token = tokenInfo.token
pair = tokenInfo.lp;
decimal = tokenInfo.decimal;
const now : any = new Date();
const targetTime : any = new Date(tokenInfo.startTime.getFullYear(), tokenInfo.startTime.getMonth(),tokenInfo.startTime.getDate(), tokenInfo.startTime.getHours(), tokenInfo.startTime.getMinutes(), tokenInfo.startTime.getSeconds(),tokenInfo.startTime.getMilliseconds());
const timeDiff : any = targetTime - now;
const msUntilTarget = timeDiff > 0 ? timeDiff : 86400000 - Math.abs(timeDiff);
if(now >= targetTime){
await orderBuys(tokenInfo.token.toString(),tokenInfo.lp.toString(),Number(tokenInfo.decimal))
}
const MAX_RETRIES = 10000;
const BASE_DELAY = 1000;
let retries = 0;
let delay = BASE_DELAY;
const Addr = new PublicKey(tokenInfo.vault)
let profit : Number;
const subscriptionID = connection.onAccountChange(
Addr,
async(updatedAccountInfo, context) => {
const Bal= updatedAccountInfo.lamports/1000000000
const prof = Number(Bal) / Number(tokenInfo?.vaultBalance);
console.log(prof);
while (retries < MAX_RETRIES) {
try {
await ctx.reply(
`
${tokenInfo.tokenSym} : ${tokenInfo.token}
SOL : So11111111111111111111111111111111111111112
${Number(tokenInfo.vaultBalance).toFixed(2)} SOL
Profit : ${Number(prof).toFixed(2)}x
`
)
return;
} catch (error) {
if (error.response && error.response.error_code === 429) {
console.log(`Profit on console.. TG in ${delay}ms...`);
await new Promise(resolve => setTimeout(resolve, delay));
retries++;
delay *= 1.5; // double the delay for each retry
if (delay > 60000) { // limit the maximum delay to 60 seconds
delay = 60000;
}
} else {
throw error;
}
}
}
throw new Error('Max retries exceeded');
}
)
}
}
}
});
bot.launch()
async function info(pair) {
const SOLANA : string = 'So11111111111111111111111111111111111111112';
let vault;
let check;
// for(const trade of array){
// pair = trade;
// }
if(pair == undefined || pair == null){
console.log(`it is null`)
}else{
const mint = new anchor.web3.PublicKey(
pair
);
const [metadataPDA] = anchor.web3.PublicKey.findProgramAddressSync(
[
Buffer.from("metadata"),
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
],
TOKEN_METADATA_PROGRAM_ID
);
const accInfo = await connection.getAccountInfo(metadataPDA);
const metadata = Metadata.deserialize(accInfo.data, 0);
const tokenName = metadata[0].data.name;
const tokenSym = metadata[0].data.symbol;
const data:any = await queryLpMintInfo(pair,SOLANA);
const info = data.Raydium_LiquidityPoolv4[0];
if(info == null){
return null
}else{
let ownerBalance;
const openTime = info.poolOpenTime;
const startTime = new Date(openTime * 1000);
const token : String = info.baseMint
const tokenVault : String = info.baseVault
const solVault: String = info.quoteVault;
const lp = info.pubkey
const decimal = info.baseDecimal;
// const qvault = info.quoteVault;
const owner = metadata[0].updateAuthority;
const lpReserve = info.lpReserve;
const ownerInfo = await connection.getAccountInfo(new PublicKey(owner))
if(ownerInfo == null){
ownerBalance = "Renounced"
}else{
ownerBalance = await ownerInfo.lamports/1000000000;
}
const tokenAddress = new PublicKey(solVault)
vault = solVault
check = await connection.getTokenAccountBalance(
tokenAddress
)
const vaultBalance = await check.value.uiAmount;
// const successful = await orderBuys(msUntilTarget,token.toString(),lp.toString(),Number(decimal))
return {
tokenName,
tokenSym,
lp,
vaultBalance,
startTime,
token,
decimal,
vault,
owner,
// successful,
ownerBalance
}
}
}
}
async function queryLpMintInfo(token: string, sol: string) {
// See how we are only querying what we need
const query = gql`
query MyQuery ($where: Raydium_LiquidityPoolv4_bool_exp) {
Raydium_LiquidityPoolv4(
where: $where
) {
baseMint
lpMint
lpReserve
baseVault
poolOpenTime
lpVault
quoteMint
quoteVault
baseDecimal
owner
pubkey
}
}`;
const variables = {
where: {
baseMint: {
_eq: token,
},
quoteMint: {
_eq: sol,
},
},
};
return await graphQLClient.request(query, variables);
}
async function orderBuys(token,pool, decimal) {
await Buy(token,pool,amount,decimal);
};
async function orderSell(token,pool,decimal) {
const tokenAdd = new PublicKey(token);
const tokenAddress = await getOrCreateAssociatedTokenAccount(connection,wallet, tokenAdd ,wallet.publicKey )// RAY
const balance = Number(tokenAddress.amount);
await Sell(token,pool,balance,decimal);
return true;
}