forked from warp-id/solana-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
219 lines (190 loc) · 7.44 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { MarketCache, PoolCache } from './cache';
import { Listeners } from './listeners';
import { Connection, KeyedAccountInfo, Keypair } from '@solana/web3.js';
import { LIQUIDITY_STATE_LAYOUT_V4, MARKET_STATE_LAYOUT_V3, Token, TokenAmount } from '@raydium-io/raydium-sdk';
import { AccountLayout, getAssociatedTokenAddressSync } from '@solana/spl-token';
import { Bot, BotConfig } from './bot';
import { DefaultTransactionExecutor, TransactionExecutor } from './transactions';
import {
getToken,
getWallet,
logger,
COMMITMENT_LEVEL,
RPC_ENDPOINT,
RPC_WEBSOCKET_ENDPOINT,
PRE_LOAD_EXISTING_MARKETS,
LOG_LEVEL,
CHECK_IF_MINT_IS_RENOUNCED,
CHECK_IF_BURNED,
QUOTE_MINT,
MAX_POOL_SIZE,
MIN_POOL_SIZE,
QUOTE_AMOUNT,
PRIVATE_KEY,
USE_SNIPE_LIST,
ONE_TOKEN_AT_A_TIME,
AUTO_SELL_DELAY,
MAX_SELL_RETRIES,
AUTO_SELL,
MAX_BUY_RETRIES,
AUTO_BUY_DELAY,
COMPUTE_UNIT_LIMIT,
COMPUTE_UNIT_PRICE,
CACHE_NEW_MARKETS,
TAKE_PROFIT,
STOP_LOSS,
BUY_SLIPPAGE,
SELL_SLIPPAGE,
PRICE_CHECK_DURATION,
PRICE_CHECK_INTERVAL,
SNIPE_LIST_REFRESH_INTERVAL,
TRANSACTION_EXECUTOR,
WARP_FEE,
} from './helpers';
import { version } from './package.json';
import { WarpTransactionExecutor } from './transactions/warp-transaction-executor';
const connection = new Connection(RPC_ENDPOINT, {
wsEndpoint: RPC_WEBSOCKET_ENDPOINT,
commitment: COMMITMENT_LEVEL,
});
function printDetails(wallet: Keypair, quoteToken: Token, bot: Bot) {
logger.info(`
.. :-===++++-
.-==+++++++- =+++++++++-
..:::--===+=.=: .+++++++++++:=+++++++++:
.==+++++++++++++++=:+++: .+++++++++++.=++++++++-.
.-+++++++++++++++=:=++++- .+++++++++=:.=+++++-::-.
-:+++++++++++++=:+++++++- .++++++++-:- =+++++=-:
-:++++++=++++=:++++=++++= .++++++++++- =+++++:
-:++++-:=++=:++++=:-+++++:+++++====--:::::::.
::=+-:::==:=+++=::-:--::::::::::---------::.
::-: .::::::::. --------:::..
:- .:.-:::.
WARP DRIVE ACTIVATED 🚀🐟
Made with ❤️ by humans.
Version: ${version}
`);
const botConfig = bot.config;
logger.info('------- CONFIGURATION START -------');
logger.info(`Wallet: ${wallet.publicKey.toString()}`);
logger.info('- Bot -');
logger.info(`Using warp: ${bot.isWarp}`);
if (bot.isWarp) {
logger.info(`Warp fee: ${WARP_FEE}`);
}
else {
logger.info(`Compute Unit limit: ${botConfig.unitLimit}`);
logger.info(`Compute Unit price (micro lamports): ${botConfig.unitPrice}`);
}
logger.info(`Single token at the time: ${botConfig.oneTokenAtATime}`);
logger.info(`Pre load existing markets: ${PRE_LOAD_EXISTING_MARKETS}`);
logger.info(`Cache new markets: ${CACHE_NEW_MARKETS}`);
logger.info(`Log level: ${LOG_LEVEL}`);
logger.info('- Buy -');
logger.info(`Buy amount: ${botConfig.quoteAmount.toFixed()} ${botConfig.quoteToken.name}`);
logger.info(`Auto buy delay: ${botConfig.autoBuyDelay} ms`);
logger.info(`Max buy retries: ${botConfig.maxBuyRetries}`);
logger.info(`Buy amount (${quoteToken.symbol}): ${botConfig.quoteAmount.toFixed()}`);
logger.info(`Buy slippage: ${botConfig.buySlippage}%`);
logger.info('- Sell -');
logger.info(`Auto sell: ${AUTO_SELL}`);
logger.info(`Auto sell delay: ${botConfig.autoSellDelay} ms`);
logger.info(`Max sell retries: ${botConfig.maxSellRetries}`);
logger.info(`Sell slippage: ${botConfig.sellSlippage}%`);
logger.info(`Price check interval: ${botConfig.priceCheckInterval} ms`);
logger.info(`Price check duration: ${botConfig.priceCheckDuration} ms`);
logger.info(`Take profit: ${botConfig.takeProfit}%`);
logger.info(`Stop loss: ${botConfig.stopLoss}%`);
logger.info('- Filters -');
logger.info(`Snipe list: ${botConfig.useSnipeList}`);
logger.info(`Snipe list refresh interval: ${SNIPE_LIST_REFRESH_INTERVAL} ms`);
logger.info(`Check renounced: ${botConfig.checkRenounced}`);
logger.info(`Check burned: ${botConfig.checkBurned}`);
logger.info(`Min pool size: ${botConfig.minPoolSize.toFixed()}`);
logger.info(`Max pool size: ${botConfig.maxPoolSize.toFixed()}`);
logger.info('------- CONFIGURATION END -------');
logger.info('Bot is running! Press CTRL + C to stop it.');
}
const runListener = async () => {
logger.level = LOG_LEVEL;
logger.info('Bot is starting...');
const marketCache = new MarketCache(connection);
const poolCache = new PoolCache();
let txExecutor: TransactionExecutor;
switch (TRANSACTION_EXECUTOR) {
case 'warp': {
txExecutor = new WarpTransactionExecutor(WARP_FEE);
break;
}
default: {
txExecutor = new DefaultTransactionExecutor(connection);
break;
}
}
const wallet = getWallet(PRIVATE_KEY.trim());
const quoteToken = getToken(QUOTE_MINT);
const botConfig = <BotConfig>{
wallet,
quoteAta: getAssociatedTokenAddressSync(quoteToken.mint, wallet.publicKey),
checkRenounced: CHECK_IF_MINT_IS_RENOUNCED,
checkBurned: CHECK_IF_BURNED,
minPoolSize: new TokenAmount(quoteToken, MIN_POOL_SIZE, false),
maxPoolSize: new TokenAmount(quoteToken, MAX_POOL_SIZE, false),
quoteToken,
quoteAmount: new TokenAmount(quoteToken, QUOTE_AMOUNT, false),
oneTokenAtATime: ONE_TOKEN_AT_A_TIME,
useSnipeList: USE_SNIPE_LIST,
autoSellDelay: AUTO_SELL_DELAY,
maxSellRetries: MAX_SELL_RETRIES,
autoBuyDelay: AUTO_BUY_DELAY,
maxBuyRetries: MAX_BUY_RETRIES,
unitLimit: COMPUTE_UNIT_LIMIT,
unitPrice: COMPUTE_UNIT_PRICE,
takeProfit: TAKE_PROFIT,
stopLoss: STOP_LOSS,
buySlippage: BUY_SLIPPAGE,
sellSlippage: SELL_SLIPPAGE,
priceCheckInterval: PRICE_CHECK_INTERVAL,
priceCheckDuration: PRICE_CHECK_DURATION,
};
const bot = new Bot(connection, marketCache, poolCache, txExecutor, botConfig);
const valid = await bot.validate();
if (!valid) {
logger.info('Bot is exiting...');
process.exit(1);
}
if (PRE_LOAD_EXISTING_MARKETS) {
await marketCache.init({ quoteToken });
}
const runTimestamp = Math.floor(new Date().getTime() / 1000);
const listeners = new Listeners(connection);
await listeners.start({
walletPublicKey: wallet.publicKey,
quoteToken,
autoSell: AUTO_SELL,
cacheNewMarkets: CACHE_NEW_MARKETS,
});
listeners.on('market', (updatedAccountInfo: KeyedAccountInfo) => {
const marketState = MARKET_STATE_LAYOUT_V3.decode(updatedAccountInfo.accountInfo.data);
marketCache.save(updatedAccountInfo.accountId.toString(), marketState);
});
listeners.on('pool', async (updatedAccountInfo: KeyedAccountInfo) => {
const poolState = LIQUIDITY_STATE_LAYOUT_V4.decode(updatedAccountInfo.accountInfo.data);
const poolOpenTime = parseInt(poolState.poolOpenTime.toString());
const exists = await poolCache.get(poolState.baseMint.toString());
//asd
if (!exists && (poolOpenTime > runTimestamp || true)) {
poolCache.save(updatedAccountInfo.accountId.toString(), poolState);
await bot.buy(updatedAccountInfo.accountId, poolState);
}
});
listeners.on('wallet', async (updatedAccountInfo: KeyedAccountInfo) => {
const accountData = AccountLayout.decode(updatedAccountInfo.accountInfo.data);
if (accountData.mint.equals(quoteToken.mint)) {
return;
}
await bot.sell(updatedAccountInfo.accountId, accountData);
});
printDetails(wallet, quoteToken, bot);
};
runListener();