-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
160 lines (134 loc) · 4.01 KB
/
main.ts
File metadata and controls
160 lines (134 loc) · 4.01 KB
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
import {
VersionedTransaction,
Keypair,
SystemProgram,
Transaction,
Connection,
ComputeBudgetProgram,
TransactionInstruction,
TransactionMessage,
AddressLookupTableProgram,
PublicKey,
SYSVAR_RENT_PUBKEY,
} from "@solana/web3.js";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
getAssociatedTokenAddressSync,
NATIVE_MINT,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import { pumpswap } from "./src/pumpswap-idl.json"
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { AnchorProvider } from "@coral-xyz/anchor";
import base58 from "bs58";
import {
DESCRIPTION,
DISTRIBUTION_WALLETNUM,
FILE,
global_mint,
JITO_FEE,
PRIVATE_KEY,
PUMP_PROGRAM,
RPC_ENDPOINT,
RPC_WEBSOCKET_ENDPOINT,
SWAP_AMOUNT,
TELEGRAM,
TOKEN_CREATE_ON,
TOKEN_NAME,
TOKEN_SHOW_NAME,
TOKEN_SYMBOL,
TWITTER,
WEBSITE,
} from "./constants";
import { saveDataToFile, sleep } from "./utils";
import { createAndSendV0Tx, execute } from "./executor/legacy";
import { PumpFunSDK } from "./src/pumpfun";
import { executeJitoTx } from "./executor/jito";
const commitment = "confirmed";
const connection = new Connection(RPC_ENDPOINT, {
wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
commitment,
});
const mainKp = Keypair.fromSecretKey(base58.decode(PRIVATE_KEY));
let kps: Keypair[] = [];
const transactions: VersionedTransaction[] = [];
const mintKp = Keypair.generate();
const mintAddress = mintKp.publicKey;
const sdk = new PumpFunSDK(
new AnchorProvider(connection, new NodeWallet(mainKp), { commitment })
);
const pumpswap = async () => {
console.log("Starting pumpswap process...");
// Define and init token addresses
const userTokenAddress = getAssociatedTokenAddressSync(
mintAddress,
mainKp.publicKey
);
console.log("User Token Address: ", userTokenAddress.toBase58());
// Add new mint token & create an associated token account for the mint
try {
const tx = new Transaction().add(
SystemProgram.createAccount({
fromPubkey: mainKp.publicKey,
newAccountPubkey: mintAddress,
lamports: await connection.getMinimumBalanceForRentExemption(82),
space: 82,
programId: TOKEN_PROGRAM_ID,
})
);
tx.add(
Token.createInitMintInstruction(
TOKEN_PROGRAM_ID,
mintAddress,
9,
mainKp.publicKey,
mainKp.publicKey
)
);
tx.add(
Token.createAssociatedTokenAccountInstruction(
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
mintAddress,
userTokenAddress,
mainKp.publicKey,
mainKp.publicKey
)
);
console.log("Sending transaction to create and initialize token...");
await connection.sendTransaction(tx, [mainKp, mintKp], {
skipPreflight: false,
preflightCommitment: "confirmed",
});
console.log("Token and associated account created successfully.");
} catch (error) {
console.error("Failed during mint or ATA creation: ", error);
throw error;
}
// Logic for Swapping tokens (placeholder)
try {
console.log("Swapping tokens...");
const swapTx = await sdk.tokenSwapInstructions({
fromToken: NATIVE_MINT, // Assume native SOL for this swap; substitute as needed
toToken: mintAddress,
amount: SWAP_AMOUNT, // Taken from constants
userPublicKey: mainKp.publicKey,
});
console.log("Executing token swap transaction...");
const swapResult = await createAndSendV0Tx(connection, swapTx, [mainKp]);
console.log("Swap completed. Transaction hash: ", swapResult);
} catch (swapError) {
console.error("Error during token swap: ", swapError);
throw swapError;
}
console.log("Pumpswap process completed!");
};
const main = async () => {
console.log("Starting main execution...");
try {
await pumpswap();
} catch (err) {
console.error("Error in the pumpswap main process: ", err);
}
};
main();