forked from bigmovers/solana-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjitoPool.ts
143 lines (117 loc) · 5.87 KB
/
jitoPool.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
import { connection, wallet, walletconn, RayLiqPoolv4, tipAcct } from "../config";
import { PublicKey, ComputeBudgetProgram, VersionedTransaction, TransactionInstruction, TransactionMessage, SystemProgram, Keypair, LAMPORTS_PER_SOL, AddressLookupTableAccount } from '@solana/web3.js';
import { DEFAULT_TOKEN, LP_MINT_ASSOCIATED_SEED, PROGRAMIDS, addLookupTableInfo, makeTxVersion } from './clients/constants';
import { TOKEN_PROGRAM_ID, getMint } from '@solana/spl-token';
import { Liquidity, MARKET_STATE_LAYOUT_V3, Token, TokenAmount, Market, MAINNET_PROGRAM_ID } from "@raydium-io/raydium-sdk";
import { BN } from "@project-serum/anchor";
import { ammCreatePool, getWalletTokenAccount } from "./clients/raydiumUtil";
import { promises as fsPromises } from 'fs';
import { loadKeypairs } from './createKeys';
import { lookupTableProvider } from "./clients/LookupTableProvider";
//import { getRandomTipAccount } from "./clients/config";
import { searcherClient } from "./clients/jito";
import { Bundle as JitoBundle } from 'jito-ts/dist/sdk/block-engine/types.js';
import promptSync from 'prompt-sync';
import * as spl from '@solana/spl-token';
import { IPoolKeys } from './clients/interfaces';
import { derivePoolKeys } from "./clients/poolKeysReassigned";
import path from 'path';
import fs from 'fs';
const prompt = promptSync();
const keyInfoPath = path.join(__dirname, 'keyInfo.json');
type LiquidityPairTargetInfo = {
baseToken: Token;
quoteToken: Token;
targetMarketId: PublicKey;
};
type AssociatedPoolKeys = {
lpMint: PublicKey;
id: PublicKey;
baseMint: PublicKey;
quoteMint: PublicKey;
};
export async function buyBundle() {
const bundledTxns: VersionedTransaction[] = [];
const keypairs: Keypair[] = loadKeypairs();
let poolInfo: { [key: string]: any } = {};
if (fs.existsSync(keyInfoPath)) {
const data = fs.readFileSync(keyInfoPath, 'utf-8');
poolInfo = JSON.parse(data);
}
const lut = new PublicKey(poolInfo.addressLUT.toString());
const lookupTableAccount = (
await connection.getAddressLookupTable(lut)
).value;
if (lookupTableAccount == null) {
console.log("Lookup table account not found!");
process.exit(0);
}
// -------- step 1: ask necessary questions for pool build --------
const baseAddr = prompt('Token address: ') || '';
const percentOfSupplyInput = prompt('% of your token balance in pool (Ex. 80): ') || '0';
const solInPoolInput = prompt('# of SOL in LP (Ex. 10): ') || '0';
const OpenBookID = prompt('OpenBook MarketID: ') || '';
const jitoTipAmtInput = prompt('Jito tip in Sol (Ex. 0.01): ') || '0';
const iterations = parseInt(prompt('Enter the number of iterations for bundle creation: ') || '0', 10);
const delaySeconds = parseInt(prompt('Enter the delay between each iteration in seconds: ') || '0', 10);
const jitoTipAmt = parseFloat(jitoTipAmtInput) * LAMPORTS_PER_SOL;
const percentOfSupply = parseFloat(percentOfSupplyInput);
const solInPool = parseFloat(solInPoolInput);
let myToken = new PublicKey(baseAddr)
let tokenInfo = await getMint(connection, myToken, 'finalized', TOKEN_PROGRAM_ID)
const TokenBalance = await fetchTokenBalance(baseAddr, tokenInfo.decimals);
const baseToken = new Token(TOKEN_PROGRAM_ID, new PublicKey(tokenInfo.address), tokenInfo.decimals) // Token
const quoteToken = DEFAULT_TOKEN.SOL // SOL
const targetMarketId = new PublicKey(OpenBookID)
for (let i = 0; i < iterations; i++) {
// -------- step 2: create pool txn --------
const startTime = Math.floor(Date.now() / 1000);
const walletTokenAccounts = await getWalletTokenAccount(connection, wallet.publicKey)
const marketBufferInfo: any = await connection.getAccountInfo(targetMarketId)
const {
baseMint,
quoteMint,
baseLotSize,
quoteLotSize,
baseVault,
quoteVault,
bids,
asks,
eventQueue,
requestQueue
} = MARKET_STATE_LAYOUT_V3.decode(marketBufferInfo.data)
let poolKeys: any = Liquidity.getAssociatedPoolKeys({
version: 4,
marketVersion: 3,
baseMint,
quoteMint,
baseDecimals: tokenInfo.decimals,
quoteDecimals: 9,
marketId: targetMarketId,
programId: PROGRAMIDS.AmmV4,
marketProgramId: PROGRAMIDS.OPENBOOK_MARKET
})
poolKeys.marketBaseVault = baseVault;
poolKeys.marketQuoteVault = quoteVault;
poolKeys.marketBids = bids;
poolKeys.marketAsks = asks;
poolKeys.marketEventQueue = eventQueue;
//console.log("Pool Keys:", poolKeys);
// Ensure percentOfSupply and TokenBalance are scaled to integers if they involve decimals.
const baseMintAmount = new BN(Math.floor((percentOfSupply / 100) * TokenBalance).toString());
// Ensure solInPool is scaled to an integer if it involves decimals.
const quoteMintAmount = new BN((solInPool * Math.pow(10, 9)).toString());
// If you need to clone the BN instances for some reason, this is correct. Otherwise, you can use baseMintAmount and quoteMintAmount directly.
const addBaseAmount = new BN(baseMintAmount.toString());
const addQuoteAmount = new BN(quoteMintAmount.toString());
// Fetch LP Mint and write to json
const associatedPoolKeys = getMarketAssociatedPoolKeys({
baseToken,
quoteToken,
targetMarketId,
});
await writeDetailsToJsonFile(associatedPoolKeys, startTime);
[[ REDACTED ]]
[[470 lines left]]
[[this is only a file from the whole project]]
[[ @benoriz0 on telegram]]