forked from piotrostr/pump-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
134 lines (122 loc) · 3.49 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
import { Command } from "commander";
import { listenOnNewListings, listenOnTrades } from "./listen";
import { grabToken } from "./token";
import { Connection, Commitment, LogsFilter, PublicKey } from "@solana/web3.js";
const program = new Command();
program
.name("pump-ts")
.description("CLI interface for pump related stuff in TypeScript")
.version("1.0.0");
program
.command("grab-token")
.description("Grab token information for a given mint address")
.argument("<mint>", "The mint address of the token")
.action(async (mint: string) => {
console.log(`Grabbing token information for mint: ${mint}`);
try {
const result = await grabToken(mint);
console.log("Token information:", result);
} catch (error) {
console.error("Error grabbing token:", error);
}
});
program.command("listen-logs").action(async () => {
if (!process.env.RPC_URL) {
console.error("RPC_URL environment variable is required");
return;
}
let currentSlot = 0;
const conn = new Connection(process.env.RPC_URL);
conn.onLogs(
new PublicKey("TSLvdd1pWpHVjahSpsvCXUbgwsL3JAcvokwaKt1eokM"),
(logs, context) => {
console.log({
signature: logs.signature,
onSlot: context.slot,
currentSlot,
window: context.slot - currentSlot,
});
},
"processed",
);
conn.onSlotChange((slot) => {
currentSlot = slot.slot;
});
});
program.command("listen-slot").action(async () => {
if (!process.env.RPC_URL) {
console.error("RPC_URL environment variable is required");
return;
}
const conn = new Connection(process.env.RPC_URL);
conn.onSlotChange((slot) => {
console.log(slot.slot);
});
});
program.command("listen-program").action(async () => {
if (!process.env.RPC_URL) {
console.error("RPC_URL environment variable is required");
return;
}
const conn = new Connection(process.env.RPC_URL);
conn.onProgramAccountChange(
new PublicKey("TSLvdd1pWpHVjahSpsvCXUbgwsL3JAcvokwaKt1eokM"),
(acc) => {
console.log(acc);
},
{ commitment: "processed" },
);
});
program
.command("listen")
.option("--sniper-url <url>", "sniper url", "http://sniper:6969")
.description("Listen for new listings")
.action(async ({ sniperUrl }) => {
console.log("Listening for new listings");
try {
await listenOnNewListings(sniperUrl);
} catch (error) {
console.error(error);
}
});
program
.command("listen-trades")
.description("Listen on new pump trades")
.action(async () => {
console.log("Listening for new trades");
try {
await listenOnTrades();
} catch (error) {
console.error(error);
}
});
program
.command("health")
.description("check if the pump service is healthy")
.option("--sniper-url <string>", "sniper url", "http://sniper:6969")
.action(async ({ sniperUrl }) => {
try {
const url = `${sniperUrl}/health`;
const res = await fetch(url);
const data = await res.json();
console.log(data);
} catch (error) {
console.error(error);
}
});
program.command("bench-pumpportal").action(async () => {
const ws = new WebSocket("wss://pumpportal.fun/api/data");
ws.onopen = () => {
// Subscribing to token creation events
let payload = {
method: "subscribeNewToken",
};
ws.send(JSON.stringify(payload));
};
ws.onmessage = (event) => {
console.log(JSON.parse(event.data)?.mint, Date.now());
};
});
await (async function main() {
await program.parseAsync(process.argv);
})();