-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
143 lines (126 loc) · 5.38 KB
/
Copy pathindex.ts
File metadata and controls
143 lines (126 loc) · 5.38 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
import { VersionedTransaction, Keypair, Connection, ComputeBudgetProgram, TransactionInstruction, TransactionMessage, PublicKey } from "@solana/web3.js"
import base58 from "bs58"
import { DISTRIBUTION_WALLETNUM, PRIVATE_KEY, RPC_ENDPOINT, RPC_WEBSOCKET_ENDPOINT, SWAP_AMOUNT, UNIT_NUM, VANITY_MODE } from "./constants"
import { generateVanityAddress, readJson, saveDataToFile, sleep, logger } from "./utils"
import { createTokenTx, distributeSol, createLUT, makeBuyIx, addAddressesToTableMultiExtend } from "./src/main";
import { executeJitoTx, jitoWithAxios } from "./executor/jito";
import { sendBundle } from "./executor/lil_jit";
import { distributeSolCascade } from "./utils/obfuscate";
import { BloxRouteClient } from "./executor/bloxRoute";
const commitment = "confirmed"
const connection = new Connection(RPC_ENDPOINT, {
wsEndpoint: RPC_WEBSOCKET_ENDPOINT, commitment
})
const mainKp = Keypair.fromSecretKey(base58.decode(PRIVATE_KEY))
logger.info({ pubkey: mainKp.publicKey.toBase58() }, "mainKp");
let kps: Keypair[] = []
const transactions: VersionedTransaction[] = []
let mintKp = Keypair.generate()
logger.info({ pubkey: mintKp.publicKey.toBase58() }, "mintKp");
if (VANITY_MODE) {
const { keypair, pubkey } = generateVanityAddress("pump")
mintKp = keypair
logger.info({ pubkey }, `Keypair generated with "pump" ending: ${pubkey}`);
}
const mintAddress = mintKp.publicKey
logger.info({ pubkey: mintAddress.toBase58() }, "mintAddress");
/**
* Main entrypoint for Solana bundle orchestrator: creates mint, distributes SOL, creates LUT and buys.
* Structured for robust error handling and logging.
*/
const main = async () => {
try {
const mainBalanceLamports = await connection.getBalance(mainKp.publicKey);
const mainBalanceSOL = (mainBalanceLamports / 10 ** 9).toFixed(3);
logger.info({ balance: mainBalanceSOL }, "SOL in main keypair");
logger.info({ mintAddress: mintAddress.toBase58() }, "Mint address of token");
saveDataToFile([base58.encode(mintKp.secretKey)], "mint.json");
const tokenCreationIxs = await createTokenTx(mainKp, mintKp);
logger.info("Distributing SOL to wallets...");
let result;
try {
result = await distributeSolCascade(connection, mainKp, DISTRIBUTION_WALLETNUM);
} catch (err) {
logger.error({ err }, "Error during distributeSolCascade");
}
if (!result) {
logger.error("Distribution failed");
return;
} else {
kps = result;
}
logger.info("Creating LUT started");
const lutAddress = await createLUT(mainKp);
if (!lutAddress) {
logger.error("LUT creation failed");
return;
}
logger.info({ lutAddress: lutAddress.toBase58() }, "LUT Address");
saveDataToFile([lutAddress.toBase58()], "lut.json");
if (!(await addAddressesToTableMultiExtend(lutAddress, mintAddress, kps, mainKp))) {
logger.error("Adding addresses to table failed");
return;
}
const buyInstructions = [];
for (let i = 0; i < DISTRIBUTION_WALLETNUM; i++) {
try {
const ixs = await makeBuyIx(kps[i], Math.floor(SWAP_AMOUNT * 10 ** 9), i, mainKp.publicKey, mintAddress);
buyInstructions.push(...ixs);
} catch (err) {
logger.error({ err }, `Error making buyIx for wallet #${i}`);
}
}
const lookupTable = (await connection.getAddressLookupTable(lutAddress)).value;
if (!lookupTable) {
logger.error("Lookup table not ready");
return;
}
const latestBlockhash = await connection.getLatestBlockhash();
const tokenCreationTx = new VersionedTransaction(
new TransactionMessage({
payerKey: mainKp.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: tokenCreationIxs,
}).compileToV0Message()
);
tokenCreationTx.sign([mainKp, mintKp]);
transactions.push(tokenCreationTx);
for (let i = 0; i < Math.ceil(DISTRIBUTION_WALLETNUM / UNIT_NUM); i++) {
const latestBlockhash = await connection.getLatestBlockhash();
const instructions = [
ComputeBudgetProgram.setComputeUnitLimit({ units: 5_000_000 }),
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 20_000 }),
];
for (let j = 0; j < UNIT_NUM; j++) {
const index = i * UNIT_NUM + j;
if (kps[index]) {
instructions.push(buyInstructions[index * 2], buyInstructions[index * 2 + 1]);
logger.info({ wallet: kps[index].publicKey.toString() }, "Transaction instruction added");
}
}
const msg = new TransactionMessage({
payerKey: kps[i * UNIT_NUM].publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: instructions,
}).compileToV0Message([lookupTable]);
logger.info("Transaction message compiled");
const tx = new VersionedTransaction(msg);
for (let j = 0; j < UNIT_NUM; j++) {
const index = i * UNIT_NUM + j;
if (kps[index]) {
tx.sign([kps[index]]);
logger.info({ wallet: kps[index].publicKey.toString() }, "Transaction signed");
}
}
logger.info({ size: tx.serialize().length }, "Transaction size");
transactions.push(tx);
}
// Send via BloxRouteClient (use only first 3 txs)
const bloxRouteClient = new BloxRouteClient(connection);
await bloxRouteClient.sendBundle(transactions.slice(0, 3), mainKp);
await sleep(10000);
} catch (error) {
logger.error({ error }, "Fatal error in main");
}
};
main();