-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoolBuy.ts
161 lines (147 loc) · 5.2 KB
/
poolBuy.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
import { Keypair, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js"
import {
DEVNET_PROGRAM_ID,
jsonInfo2PoolKeys,
Liquidity,
MAINNET_PROGRAM_ID,
MARKET_STATE_LAYOUT_V3, LiquidityPoolKeys,
Token, TokenAmount, ZERO, ONE, TEN,
TOKEN_PROGRAM_ID, parseBigNumberish, bool,
buildSimpleTransaction,
TxVersion
} from "@raydium-io/raydium-sdk"
import { unpackMint } from "@solana/spl-token";
import base58 from "bs58"
import BN from "bn.js"
import { addLookupTableInfo, cluster, makeTxVersion, poolCreationInterval, tokens } from "./config"
import { createMarket } from "./src/createMarket"
import { createTokenWithMetadata } from "./src/createTokenPinata"
import { outputBalance, readJson, retrieveEnvVariable, saveDataToFile, sleep } from "./src/utils"
import { PoolInfo, UserToken } from './src/types'
import {
getTokenAccountBalance,
assert,
getWalletTokenAccount,
} from "./utils/get_balance";
import { buildAndSendTx, build_swap_instructions, build_create_pool_instructions } from "./utils/build_a_sendtxn";
import {
connection,
LP_wallet_keypair, swap_wallet_keypair,
quote_Mint_amount,
input_baseMint_tokens_percentage,
lookupTableCache,
delay_pool_open_time, DEFAULT_TOKEN, swap_sol_amount,
swapWallets
} from "./config";
import { jitoWithAxios } from "./src/jitoWithAxios";
import { token } from "@metaplex-foundation/js";
import { executeVersionedTx } from "./src/execute";
import { txCreateNewPoolAndBundleBuy } from "./src/createPoolAndBundleBuy";
import { ammRemoveLiquidity } from "./src/removeLiquidity";
type WalletTokenAccounts = Awaited<ReturnType<typeof getWalletTokenAccount>>
const recoveryMode = retrieveEnvVariable("RECOVERY_MODE") == "true"
const programId = cluster == "devnet" ? DEVNET_PROGRAM_ID : MAINNET_PROGRAM_ID
const single = async (token: UserToken) => {
let params: PoolInfo
try {
// if (recoveryMode == true) {
// const data = readJson()
// if (!data.mainKp) {
// console.log("Main keypair is not set")
// return
// }
// params = {
// mint: data.mint ? new PublicKey(data.mint) : null,
// marketId: data.marketId ? new PublicKey(data.marketId) : null,
// poolId: data.poolId ? new PublicKey(data.poolId) : null,
// mainKp: data.mainKp,
// poolKeys: null,
// removed: data.removed
// }
// } else
// params = {
// mint: null,
// marketId: null,
// poolId: null,
// mainKp: token.mainKp,
// poolKeys: null,
// removed: false
// }
// const mainKp = Keypair.fromSecretKey(base58.decode(params.mainKp!))
// if (!mainKp) {
// console.log("Main keypair is not set in recovery mode")
// return
// }
// await outputBalance(mainKp.publicKey)
// create token
// console.log("\n***************************************************************\n")
// let tokenCreationFailed = 0
// while (true) {
// if (params.mint && recoveryMode) {
// console.log("Token already created before, ", params.mint.toBase58())
// break
// }
// if (tokenCreationFailed > 5) {
// console.log("Token creation is failed in repetition, Terminate the process")
// return
// }
// const mintResult = await createTokenWithMetadata(token)
// if (!mintResult) {
// console.log("Token creation error, trying again")
// tokenCreationFailed++
// } else {
// const { amount, mint } = mintResult
// params.mint = mint
// await outputBalance(mainKp.publicKey)
// await sleep(5000)
// saveDataToFile(params)
// break
// }
// }
// create market
// console.log("\n***************************************************************\n")
// let marketCreationFailed = 0
// while (true) {
// if (params.marketId && recoveryMode) {
// console.log("Market id already created before, ", params.marketId.toBase58())
// break
// }
// if (marketCreationFailed > 5) {
// console.log("Market creation is failed in repetition, Terminate the process")
// return
// }
// const marketId = await createMarket(mainKp, params.mint)
// if (!marketId) {
// console.log("Market creation error")
// marketCreationFailed++
// } else {
// params.marketId = marketId
// await outputBalance(mainKp.publicKey)
// await sleep(3000)
// saveDataToFile(params)
// break
// }
// }
// create pool and bundle buy
// console.log("\n***************************************************************\n")
// create pool and bundle buy with several wallets
txCreateNewPoolAndBundleBuy()
// if (!params.poolId) {
// console.log("Pool id is not set in params")
// return
// }
} catch (error) {
console.log("Error happened in one of the token flow", error)
}
}
const main = async () => {
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i]
console.log(`Token ${i + 1} is to be created`)
await single(token)
// await removeLiquidity()
await sleep(10000)
console.log("One token process is ended, and go for next one")
}
}
main()