-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.ts
More file actions
75 lines (66 loc) · 2.64 KB
/
Copy pathtest.ts
File metadata and controls
75 lines (66 loc) · 2.64 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
import {
Connection,
Keypair,
PublicKey,
TransactionMessage,
VersionedTransaction,
SystemProgram,
TransactionInstruction,
} from '@solana/web3.js';
import { ComputeBudgetProgram } from '@solana/web3.js';
import { solanaConnection } from './gather';
import base58 from "bs58"
import { PRIVATE_KEY } from './constants';
import { sendBundle, simulateBundle } from './executor/lil_jit';
const mainKp = Keypair.fromSecretKey(base58.decode(PRIVATE_KEY))
const tipAccounts = [
'Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY',
'DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL',
'96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5',
'3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT',
'HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe',
'ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49',
'ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt',
'DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh',
];
const jitoFeeWallet = new PublicKey(tipAccounts[Math.floor(tipAccounts.length * Math.random())])
const receiverWallet = new PublicKey('CTeEtoFVnTjwJoDcYvJwKNEvDnQfBn3ncgBUZ1e9ybXa');
const JITO_FEE = 0.001; // example SOL
// --- Create instructions for one transaction ---
const instructions = [
ComputeBudgetProgram.setComputeUnitLimit({ units: 5_000_000 }),
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 20_000 }),
SystemProgram.transfer({
fromPubkey: mainKp.publicKey,
toPubkey: jitoFeeWallet,
lamports: Math.floor(JITO_FEE * 10 ** 9),
}),
];
// --- Another SOL transfer instruction ---
const solTransferInstructions = [
SystemProgram.transfer({
fromPubkey: mainKp.publicKey,
toPubkey: receiverWallet,
lamports: 1_000_000, // 1 SOL example
}),
];
// --- Helper to create a versioned transaction ---
async function createVersionedTx(instructionsArr: TransactionInstruction[]) {
const messageV0 = new TransactionMessage({
payerKey: mainKp.publicKey,
recentBlockhash: (await solanaConnection.getLatestBlockhash()).blockhash,
instructions: instructionsArr,
}).compileToV0Message();
return new VersionedTransaction(messageV0);
}
(async() => {
const versionedTx1 = await createVersionedTx(instructions);
console.log("1 simulate ==>", await solanaConnection.simulateTransaction(versionedTx1))
const versionedTx2 = await createVersionedTx(solTransferInstructions);
console.log("2 simulate ==>", await solanaConnection.simulateTransaction(versionedTx2))
// --- Store them in an array ---
const versionedTxArray: VersionedTransaction[] = [versionedTx1];
await simulateBundle(versionedTxArray)
const result = await sendBundle(versionedTxArray)
console.log("🚀 ~ result:", result)
})()