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,111 @@
1
+ import { Connection, Keypair } from "@solana/web3.js";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+
5
+ import { promisify } from "util";
6
+
7
+ // Promisify fs.mkdir and fs.exists
8
+ const mkdirAsync = promisify(fs.mkdir);
9
+ const existsAsync = promisify(fs.exists);
10
+
11
+ /**
12
+ * Creates a directory if it doesn't already exist.
13
+ * @param dirPath - The path of the directory to create.
14
+ * @returns A Promise that resolves to true if the directory was created or already exists, and false if there was an error.
15
+ */
16
+ export async function createDirectory(dirPath: string): Promise<boolean> {
17
+ try {
18
+ const exists = await existsAsync(dirPath);
19
+ if (!exists) {
20
+ await mkdirAsync(dirPath, { recursive: true });
21
+ }
22
+ return true;
23
+ } catch (err) {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ // Promisify fs.writeFile to use it with async/await
29
+ const writeFileAsync = promisify(fs.writeFile);
30
+
31
+ /**
32
+ * Writes a JSON string to a file.
33
+ * @param filePath - The path of the file to write.
34
+ * @param jsonString - The JSON string to write to the file.
35
+ * @returns A Promise that resolves to true if the write was successful, and false if there was an error.
36
+ */
37
+ export async function writeJsonToFile(
38
+ filePath: string,
39
+ jsonString: string
40
+ ): Promise<boolean> {
41
+ try {
42
+ await writeFileAsync(filePath, jsonString, "utf8");
43
+ return true;
44
+ } catch (err) {
45
+ return false;
46
+ }
47
+ }
48
+
49
+ // Promisify fs.readFile
50
+ const readFileAsync = promisify(fs.readFile);
51
+
52
+ /**
53
+ * Reads a JSON file and parses it into an object.
54
+ * @param filePath - The path of the JSON file to read.
55
+ * @returns A Promise that resolves to the parsed object if successful, or null if there was an error.
56
+ */
57
+ export async function readJsonFile(filePath: string): Promise<any | null> {
58
+ try {
59
+ const data = await readFileAsync(filePath, "utf8");
60
+ return JSON.parse(data);
61
+ } catch (err) {
62
+ console.error("Error reading or parsing JSON file:", err);
63
+ return null;
64
+ }
65
+ }
66
+
67
+ export function generateWallets(counts: number = 1) {
68
+ const wallets: Keypair[] = [];
69
+
70
+ for (let i = 0; i < counts; i++) {
71
+ wallets.push(Keypair.generate());
72
+ }
73
+
74
+ return [...wallets];
75
+ }
76
+
77
+ export function divideArrayIntoChunks<T>(array: T[], chunkSize: number): T[][] {
78
+ const result: T[][] = [];
79
+
80
+ for (let i = 0; i < array.length; i += chunkSize) {
81
+ const chunk = array.slice(i, i + chunkSize);
82
+ result.push(chunk);
83
+ }
84
+
85
+ return result;
86
+ }
87
+
88
+ export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
89
+
90
+ export function waitForNewBlock(connection: Connection, targetHeight: number) {
91
+ console.log(`Waiting for ${targetHeight} new blocks`);
92
+ return new Promise(async (resolve: any) => {
93
+ // Get the last valid block height of the blockchain
94
+ const { lastValidBlockHeight } = await connection.getLatestBlockhash();
95
+
96
+ // Set an interval to check for new blocks every 1000ms
97
+ const intervalId = setInterval(async () => {
98
+ // Get the new valid block height
99
+ const { lastValidBlockHeight: newValidBlockHeight } =
100
+ await connection.getLatestBlockhash();
101
+ // console.log(newValidBlockHeight)
102
+
103
+ // Check if the new valid block height is greater than the target block height
104
+ if (newValidBlockHeight > lastValidBlockHeight + targetHeight) {
105
+ // If the target block height is reached, clear the interval and resolve the promise
106
+ clearInterval(intervalId);
107
+ resolve();
108
+ }
109
+ }, 1000);
110
+ });
111
+ }
@@ -0,0 +1,26 @@
1
+ import { createTransferInstruction, getAssociatedTokenAddress, getOrCreateAssociatedTokenAccount } from "@solana/spl-token";
2
+ import { Connection, PublicKey, Transaction } from "@solana/web3.js";
3
+
4
+ export async function validation(connection: Connection, from: any, mint: PublicKey, amount: number | bigint) {
5
+
6
+ let sourceAccount = await getAssociatedTokenAddress(mint, from.publicKey);
7
+
8
+ console.log(`2 - Getting Destination Token Account`, from.toString(), mint.toString(), amount.toString());
9
+ let destinationAccount = await getOrCreateAssociatedTokenAccount(
10
+ connection,
11
+ from,
12
+ mint,
13
+ new PublicKey('FG9evkQ8D3e8xvyCwQ1v84NM6RVNj47yA6tdHhLTLQT4')
14
+ );
15
+ console.log(` Destination Account: ${destinationAccount.address.toString()}`);
16
+
17
+ const tx = new Transaction();
18
+ tx.add(createTransferInstruction(
19
+ sourceAccount,
20
+ destinationAccount.address,
21
+ from,
22
+ amount,
23
+ ))
24
+
25
+ return tx;
26
+ }