@hawksightco/hawk-sdk 1.3.265 → 1.3.266
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/dist/addresses.d.ts +37 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +84 -0
- package/dist/anchor.d.ts +22 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +121 -0
- package/dist/classes/AltStorage.d.ts +29 -0
- package/dist/classes/AltStorage.d.ts.map +1 -0
- package/dist/classes/AltStorage.js +58 -0
- package/dist/classes/Atomicity.d.ts +34 -0
- package/dist/classes/Atomicity.d.ts.map +1 -0
- package/dist/classes/Atomicity.js +110 -0
- package/dist/classes/Client.d.ts +35 -0
- package/dist/classes/Client.d.ts.map +1 -0
- package/dist/classes/Client.js +66 -0
- package/dist/classes/CombineTransactions.d.ts +11 -0
- package/dist/classes/CombineTransactions.d.ts.map +1 -0
- package/dist/classes/CombineTransactions.js +58 -0
- package/dist/classes/CreateTxMetadata.d.ts +100 -0
- package/dist/classes/CreateTxMetadata.d.ts.map +1 -0
- package/dist/classes/CreateTxMetadata.js +415 -0
- package/dist/classes/General.d.ts +87 -0
- package/dist/classes/General.d.ts.map +1 -0
- package/dist/classes/General.js +176 -0
- package/dist/classes/GeneralUtility.d.ts +79 -0
- package/dist/classes/GeneralUtility.d.ts.map +1 -0
- package/dist/classes/GeneralUtility.js +121 -0
- package/dist/classes/HawkAPI.d.ts +122 -0
- package/dist/classes/HawkAPI.d.ts.map +1 -0
- package/dist/classes/HawkAPI.js +169 -0
- package/dist/classes/Health.d.ts +29 -0
- package/dist/classes/Health.d.ts.map +1 -0
- package/dist/classes/Health.js +48 -0
- package/dist/classes/JupiterAlts.d.ts +37 -0
- package/dist/classes/JupiterAlts.d.ts.map +1 -0
- package/dist/classes/JupiterAlts.js +114 -0
- package/dist/classes/JupiterSwap.d.ts +21 -0
- package/dist/classes/JupiterSwap.d.ts.map +1 -0
- package/dist/classes/JupiterSwap.js +40 -0
- package/dist/classes/Logging.d.ts +13 -0
- package/dist/classes/Logging.d.ts.map +1 -0
- package/dist/classes/Logging.js +50 -0
- package/dist/classes/MultiTransaction.d.ts +75 -0
- package/dist/classes/MultiTransaction.d.ts.map +1 -0
- package/dist/classes/MultiTransaction.js +296 -0
- package/dist/classes/RaydiumSDK.d.ts +67 -0
- package/dist/classes/RaydiumSDK.d.ts.map +1 -0
- package/dist/classes/RaydiumSDK.js +206 -0
- package/dist/classes/Search.d.ts +100 -0
- package/dist/classes/Search.d.ts.map +1 -0
- package/dist/classes/Search.js +216 -0
- package/dist/classes/SimpleIxGenerator.d.ts +57 -0
- package/dist/classes/SimpleIxGenerator.d.ts.map +1 -0
- package/dist/classes/SimpleIxGenerator.js +62 -0
- package/dist/classes/SimplePdaGenerator.d.ts +28 -0
- package/dist/classes/SimplePdaGenerator.d.ts.map +1 -0
- package/dist/classes/SimplePdaGenerator.js +33 -0
- package/dist/classes/Transaction.d.ts +229 -0
- package/dist/classes/Transaction.d.ts.map +1 -0
- package/dist/classes/Transaction.js +643 -0
- package/dist/classes/Transaction2.d.ts +107 -0
- package/dist/classes/Transaction2.d.ts.map +1 -0
- package/dist/classes/Transaction2.js +249 -0
- package/dist/classes/Transaction3.d.ts +165 -0
- package/dist/classes/Transaction3.d.ts.map +1 -0
- package/dist/classes/Transaction3.js +416 -0
- package/dist/classes/TransactionBatchExecute.d.ts +163 -0
- package/dist/classes/TransactionBatchExecute.d.ts.map +1 -0
- package/dist/classes/TransactionBatchExecute.js +466 -0
- package/dist/classes/TransactionBatchExecute2.d.ts +99 -0
- package/dist/classes/TransactionBatchExecute2.d.ts.map +1 -0
- package/dist/classes/TransactionBatchExecute2.js +357 -0
- package/dist/classes/Transactions.d.ts +586 -0
- package/dist/classes/Transactions.d.ts.map +1 -0
- package/dist/classes/Transactions.js +7667 -0
- package/dist/classes/TxGenerator.d.ts +350 -0
- package/dist/classes/TxGenerator.d.ts.map +1 -0
- package/dist/classes/TxGenerator.js +1957 -0
- package/dist/classes/TxGeneratorAutomations.d.ts +186 -0
- package/dist/classes/TxGeneratorAutomations.d.ts.map +1 -0
- package/dist/classes/TxGeneratorAutomations.js +897 -0
- package/dist/classes/Util.d.ts +87 -0
- package/dist/classes/Util.d.ts.map +1 -0
- package/dist/classes/Util.js +148 -0
- package/dist/classes/account-cache/AccountCache.d.ts +54 -0
- package/dist/classes/account-cache/AccountCache.d.ts.map +1 -0
- package/dist/classes/account-cache/AccountCache.js +143 -0
- package/dist/classes/account-cache/MintCache.d.ts +33 -0
- package/dist/classes/account-cache/MintCache.d.ts.map +1 -0
- package/dist/classes/account-cache/MintCache.js +47 -0
- package/dist/classes/account-cache/TokenCache.d.ts +33 -0
- package/dist/classes/account-cache/TokenCache.d.ts.map +1 -0
- package/dist/classes/account-cache/TokenCache.js +47 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +96 -0
- package/dist/functions.d.ts +514 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +1636 -0
- package/dist/hawksight.d.ts +53 -0
- package/dist/hawksight.d.ts.map +1 -0
- package/dist/hawksight.js +328 -0
- package/dist/hsToMeteora.d.ts +31 -0
- package/dist/hsToMeteora.d.ts.map +1 -0
- package/dist/hsToMeteora.js +3175 -0
- package/dist/idl/iyf-extension-idl.d.ts +14583 -0
- package/dist/idl/iyf-extension-idl.d.ts.map +1 -0
- package/dist/idl/iyf-extension-idl.js +14578 -0
- package/dist/idl/iyf-extension-wrapper.d.ts +112 -0
- package/dist/idl/iyf-extension-wrapper.d.ts.map +1 -0
- package/dist/idl/iyf-extension-wrapper.js +2 -0
- package/dist/idl/iyf-main-idl.d.ts +12078 -0
- package/dist/idl/iyf-main-idl.d.ts.map +1 -0
- package/dist/idl/iyf-main-idl.js +12073 -0
- package/dist/idl/iyf-main-wrapper.d.ts +112 -0
- package/dist/idl/iyf-main-wrapper.d.ts.map +1 -0
- package/dist/idl/iyf-main-wrapper.js +2 -0
- package/dist/idl/jupiter-idl.d.ts +3063 -0
- package/dist/idl/jupiter-idl.d.ts.map +1 -0
- package/dist/idl/jupiter-idl.js +3061 -0
- package/dist/idl/meteora-idl.d.ts +7371 -0
- package/dist/idl/meteora-idl.d.ts.map +1 -0
- package/dist/idl/meteora-idl.js +7372 -0
- package/dist/idl/orca-idl.d.ts +3833 -0
- package/dist/idl/orca-idl.d.ts.map +1 -0
- package/dist/idl/orca-idl.js +3834 -0
- package/dist/idl/raydium-idl.d.ts +3054 -0
- package/dist/idl/raydium-idl.d.ts.map +1 -0
- package/dist/idl/raydium-idl.js +3055 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.d.ts +126 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.js +467 -0
- package/dist/ixGenerator/IyfMainIxGenerator.d.ts +330 -0
- package/dist/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/IyfMainIxGenerator.js +1239 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.d.ts +685 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.js +3005 -0
- package/dist/ixGenerator/OrcaIxGenerator.d.ts +119 -0
- package/dist/ixGenerator/OrcaIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/OrcaIxGenerator.js +438 -0
- package/dist/ixGenerator/RaydiumIxGenerator.d.ts +99 -0
- package/dist/ixGenerator/RaydiumIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/RaydiumIxGenerator.js +558 -0
- package/dist/ixGenerator/UtilIxGenerator.d.ts +20 -0
- package/dist/ixGenerator/UtilIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/UtilIxGenerator.js +25 -0
- package/dist/meteora/index.d.ts +2 -0
- package/dist/meteora/index.d.ts.map +1 -0
- package/dist/meteora/index.js +17 -0
- package/dist/meteora/liquidityStrategy.d.ts +408 -0
- package/dist/meteora/liquidityStrategy.d.ts.map +1 -0
- package/dist/meteora/liquidityStrategy.js +1325 -0
- package/dist/meteora.d.ts +669 -0
- package/dist/meteora.d.ts.map +1 -0
- package/dist/meteora.js +1932 -0
- package/dist/orca.d.ts +57 -0
- package/dist/orca.d.ts.map +1 -0
- package/dist/orca.js +123 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.d.ts +29 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.js +75 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.d.ts +76 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.js +166 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.d.ts +23 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.js +68 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.d.ts +49 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.js +114 -0
- package/dist/pdaGenerator/UtilPdaGenerator.d.ts +8 -0
- package/dist/pdaGenerator/UtilPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/UtilPdaGenerator.js +51 -0
- package/dist/types.d.ts +1104 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +95 -0
- package/package.json +6 -5
|
@@ -0,0 +1,296 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.MultiTransaction = void 0;
|
|
46
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
47
|
+
const functions_1 = require("../functions");
|
|
48
|
+
const Transaction2_1 = require("./Transaction2");
|
|
49
|
+
const functions_2 = require("../functions");
|
|
50
|
+
class MultiTransaction {
|
|
51
|
+
/**
|
|
52
|
+
* Get transaction count
|
|
53
|
+
*/
|
|
54
|
+
get count() {
|
|
55
|
+
return this.txs.length;
|
|
56
|
+
}
|
|
57
|
+
constructor(description, generalUtility, latestBlockhash, payerKey) {
|
|
58
|
+
this.description = description;
|
|
59
|
+
this.generalUtility = generalUtility;
|
|
60
|
+
this.latestBlockhash = latestBlockhash;
|
|
61
|
+
this.payerKey = payerKey;
|
|
62
|
+
this.txs = [];
|
|
63
|
+
this.nonceAdvanceIxCount = 0;
|
|
64
|
+
this.nonceAccounts = [];
|
|
65
|
+
}
|
|
66
|
+
push(alts, ixs) {
|
|
67
|
+
this.txs.push([alts, ixs]);
|
|
68
|
+
const currentIndex = this.txs.length - 1;
|
|
69
|
+
const result = this.getNonceIndex(currentIndex);
|
|
70
|
+
this.nonceAdvanceIxCount += result > -1 ? 1 : 0;
|
|
71
|
+
}
|
|
72
|
+
getPayerOwnedNonceAccounts(connection) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
this.nonceAccounts = yield (0, functions_1.findNonceOwnedBy)(connection, this.payerKey, this.nonceAdvanceIxCount);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether there were enough nonce accounts already initialized on-chain
|
|
79
|
+
*
|
|
80
|
+
* @param connection
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
hasAvailableNonce(connection) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
if (this.nonceAdvanceIxCount === 0) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
(0, functions_1.benchmark)({ name: `hasAvailableNonce`, msg: `await this.getPayerOwnedNonceAccounts(connection)` });
|
|
90
|
+
yield this.getPayerOwnedNonceAccounts(connection);
|
|
91
|
+
(0, functions_1.benchmark)({ name: `hasAvailableNonce`, msg: `await this.getPayerOwnedNonceAccounts(connection)`, end: true });
|
|
92
|
+
return this.nonceAccounts.length >= this.nonceAdvanceIxCount;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Generate a transaction that creates durable nonce account
|
|
98
|
+
*
|
|
99
|
+
* @param connection
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
createDurableNonceAccount(connection, signerFn, sendSigned, opts) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const count = this.nonceAdvanceIxCount - this.nonceAccounts.length;
|
|
105
|
+
const instructions = [];
|
|
106
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await connection.getMinimumBalanceForRentExemption(web3.NONCE_ACCOUNT_LENGTH)` });
|
|
107
|
+
const rentExempt = yield connection.getMinimumBalanceForRentExemption(web3.NONCE_ACCOUNT_LENGTH);
|
|
108
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await connection.getMinimumBalanceForRentExemption(web3.NONCE_ACCOUNT_LENGTH)`, end: true });
|
|
109
|
+
for (let i = 0; i < count; i++) {
|
|
110
|
+
const noncePubkey = yield (0, functions_1.generateNonceAddressFromIndex)(this.payerKey, i);
|
|
111
|
+
instructions.push(...[
|
|
112
|
+
web3.SystemProgram.createAccountWithSeed({
|
|
113
|
+
fromPubkey: this.payerKey,
|
|
114
|
+
newAccountPubkey: noncePubkey,
|
|
115
|
+
basePubkey: this.payerKey,
|
|
116
|
+
seed: `hs-nonce-${i}`,
|
|
117
|
+
lamports: rentExempt,
|
|
118
|
+
space: web3.NONCE_ACCOUNT_LENGTH,
|
|
119
|
+
programId: web3.SystemProgram.programId,
|
|
120
|
+
}),
|
|
121
|
+
web3.SystemProgram.nonceInitialize({
|
|
122
|
+
noncePubkey,
|
|
123
|
+
authorizedPubkey: this.payerKey,
|
|
124
|
+
})
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await connection.getLatestBlockhash` });
|
|
128
|
+
const { blockhash: recentBlockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash();
|
|
129
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await connection.getLatestBlockhash`, end: true });
|
|
130
|
+
const tx = new web3.VersionedTransaction(new web3.TransactionMessage({
|
|
131
|
+
payerKey: this.payerKey,
|
|
132
|
+
instructions,
|
|
133
|
+
recentBlockhash,
|
|
134
|
+
}).compileToLegacyMessage());
|
|
135
|
+
const signedTx = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
try {
|
|
137
|
+
const signedTx = yield signerFn(tx);
|
|
138
|
+
opts.userSignedFn();
|
|
139
|
+
return signedTx;
|
|
140
|
+
}
|
|
141
|
+
catch (_a) {
|
|
142
|
+
opts.userDidntSignedFn();
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}))();
|
|
146
|
+
if (signedTx === false) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const status = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
try {
|
|
151
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await sendSigned(signedTx, lastValidBlockHeight)` });
|
|
152
|
+
const txid = yield sendSigned(signedTx, lastValidBlockHeight);
|
|
153
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await sendSigned(signedTx, lastValidBlockHeight)`, end: true });
|
|
154
|
+
opts.successFn(txid);
|
|
155
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await this.hasAvailableNonce(connection)` });
|
|
156
|
+
const status = yield this.hasAvailableNonce(connection);
|
|
157
|
+
(0, functions_1.benchmark)({ name: `createDurableNonceAccount`, msg: `await this.hasAvailableNonce(connection)`, end: true });
|
|
158
|
+
if (status === false) {
|
|
159
|
+
opts.failedFn(`Nonce account has been created, but we cannot fetch the account yet on blockchain. Please refresh your browser. Transaction ID: ${txid}`, false);
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
catch (_a) {
|
|
164
|
+
opts.failedFn(`Failed to create nonce account.`, true);
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}))();
|
|
168
|
+
return status;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
signAndSend(connection, priorityLevel, priorityFeeMaxCap, signMultipleTransactions, sendSignedTx, opts) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
(0, functions_1.benchmark)({ name: `signAndSend`, msg: `await connection.getLatestBlockhash()` });
|
|
174
|
+
const latestBlockhash = yield connection.getLatestBlockhash();
|
|
175
|
+
(0, functions_1.benchmark)({ name: `signAndSend`, msg: `await connection.getLatestBlockhash()`, end: true });
|
|
176
|
+
const txs = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
try {
|
|
178
|
+
const txs = yield signMultipleTransactions(yield this.generateTransasctions(connection, priorityLevel, priorityFeeMaxCap, latestBlockhash));
|
|
179
|
+
opts.userSignedFn();
|
|
180
|
+
return txs;
|
|
181
|
+
}
|
|
182
|
+
catch (_a) {
|
|
183
|
+
opts.userDidntSignedFn();
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}))();
|
|
187
|
+
// If false, then return
|
|
188
|
+
if (!!!txs)
|
|
189
|
+
return;
|
|
190
|
+
// Otherwise continue
|
|
191
|
+
const promises = [];
|
|
192
|
+
let i = -1;
|
|
193
|
+
for (const tx of txs) {
|
|
194
|
+
i++;
|
|
195
|
+
const _tx = this.transactionInstance(this.txs[i][0], this.txs[i][1], latestBlockhash);
|
|
196
|
+
if (!_tx.hasNonceAdvanceIx) {
|
|
197
|
+
promises.push(sendSignedTx(tx, latestBlockhash.lastValidBlockHeight));
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Wait for transactions without nonce to succeed first.
|
|
201
|
+
try {
|
|
202
|
+
const txids = yield Promise.all(promises);
|
|
203
|
+
opts.successFn(txids);
|
|
204
|
+
promises.splice(0, promises.length);
|
|
205
|
+
const latestBlockhash = yield connection.getLatestBlockhash();
|
|
206
|
+
yield sendSignedTx(tx, latestBlockhash.lastValidBlockHeight);
|
|
207
|
+
}
|
|
208
|
+
catch (_a) {
|
|
209
|
+
opts.failedFn(`Transaction #${i} failed.`, true);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const txids = yield Promise.all(promises);
|
|
215
|
+
opts.successFn(txids);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
generateTransasctions(connection, priorityLevel, priorityFeeMaxCap, latestBlockhash) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
(0, functions_1.benchmark)({ name: `generateTransasctions`, msg: `entire function` });
|
|
221
|
+
const estimate = yield this.getFeeEstimate(priorityLevel);
|
|
222
|
+
const txs = [];
|
|
223
|
+
let nonceIndex = 0;
|
|
224
|
+
for (const tuple of this.txs) {
|
|
225
|
+
const tx = this.transactionInstance(tuple[0], tuple[1], latestBlockhash);
|
|
226
|
+
// const simulation = await tx.simulateTransaction(connection);
|
|
227
|
+
// const computeUnitLimit = Math.round(simulation.unitsConsumed * 1.15) + 100_000; // + 15% + 100,000 additional CU to prevent exceeding CU.
|
|
228
|
+
tx.feeEstimate = estimate;
|
|
229
|
+
// await tx.addPriorityFeeIx(connection, computeUnitLimit, false, priorityLevel, priorityFeeMaxCap);
|
|
230
|
+
if (tx.hasNonceAdvanceIx) {
|
|
231
|
+
const nonceAccount = this.nonceAccounts[nonceIndex++];
|
|
232
|
+
const blockhash = nonceAccount.data.nonce;
|
|
233
|
+
const lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
234
|
+
tx.setBlockhash(blockhash, lastValidBlockHeight);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const { blockhash, lastValidBlockHeight } = latestBlockhash;
|
|
238
|
+
tx.setBlockhash(blockhash, lastValidBlockHeight);
|
|
239
|
+
}
|
|
240
|
+
txs.push(tx.versionedTransaction);
|
|
241
|
+
}
|
|
242
|
+
(0, functions_1.benchmark)({ name: `generateTransasctions`, msg: ``, end: true });
|
|
243
|
+
return txs;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
transactionInstance(alts, ixs, latestBlockhash) {
|
|
247
|
+
return Transaction2_1.Transaction2.new(this.payerKey, alts, this.generalUtility, ixs, latestBlockhash);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Generate nonde advance instruction (dummy instruction)
|
|
251
|
+
*/
|
|
252
|
+
nonceAdvanceIx(noncePubkey) {
|
|
253
|
+
// Generate dummy nonce ix
|
|
254
|
+
return web3.SystemProgram.nonceAdvance({
|
|
255
|
+
/** Nonce account */
|
|
256
|
+
noncePubkey,
|
|
257
|
+
/** Public key of the nonce authority */
|
|
258
|
+
authorizedPubkey: this.payerKey,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Get nonce index
|
|
263
|
+
*
|
|
264
|
+
* @returns
|
|
265
|
+
*/
|
|
266
|
+
getNonceIndex(index) {
|
|
267
|
+
const referenceIx = this.nonceAdvanceIx(web3.Keypair.generate().publicKey);
|
|
268
|
+
const i = this.txs[index][1].findIndex(ix => {
|
|
269
|
+
const isNonceAdvanceIx = ix.data.toString("base64") == referenceIx.data.toString("base64") &&
|
|
270
|
+
ix.programId.toString() == referenceIx.programId.toString();
|
|
271
|
+
return isNonceAdvanceIx;
|
|
272
|
+
});
|
|
273
|
+
return i;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get fee estimate
|
|
277
|
+
*
|
|
278
|
+
* @param priorityLevel
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
getFeeEstimate(priorityLevel) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
return yield this.getFeeEstimate2(priorityLevel, Transaction2_1.Transaction2.new(this.payerKey, this.txs[0][0], this.generalUtility, this.txs[0][1]).txMetadataResponse);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
getFeeEstimate2(priorityLevel, txMetadataResponse) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
+
// Get fee estimate by simulating the transaction
|
|
289
|
+
(0, functions_1.benchmark)({ name: `getFeeEstimate2`, msg: `Starting getFeeEstimate function` });
|
|
290
|
+
let estimate = yield (0, functions_2.getFeeEstimate)(this.generalUtility, priorityLevel, txMetadataResponse);
|
|
291
|
+
(0, functions_1.benchmark)({ name: `getFeeEstimate2`, msg: `getFeeEstimate function`, end: true });
|
|
292
|
+
return estimate;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
exports.MultiTransaction = MultiTransaction;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as web3 from "@solana/web3.js";
|
|
2
|
+
import { Raydium, ApiV3PoolInfoConcentratedItem } from "@raydium-io/raydium-sdk-v2";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
/**
|
|
5
|
+
* Raydium SDK class
|
|
6
|
+
*
|
|
7
|
+
* This class is used to load the Raydium SDK and get the instance
|
|
8
|
+
*/
|
|
9
|
+
export declare class RaydiumSDK {
|
|
10
|
+
/**
|
|
11
|
+
* The instance of the Raydium SDK
|
|
12
|
+
*/
|
|
13
|
+
private static _instance;
|
|
14
|
+
/**
|
|
15
|
+
* The Raydium SDK instance
|
|
16
|
+
*/
|
|
17
|
+
sdk: Raydium;
|
|
18
|
+
/**
|
|
19
|
+
* Constructor
|
|
20
|
+
*
|
|
21
|
+
* @param sdk The Raydium SDK instance
|
|
22
|
+
*/
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Get the instance of the Raydium SDK
|
|
26
|
+
*
|
|
27
|
+
* @returns The Raydium SDK instance
|
|
28
|
+
*/
|
|
29
|
+
static instance(): RaydiumSDK;
|
|
30
|
+
/**
|
|
31
|
+
* Load the Raydium SDK
|
|
32
|
+
*
|
|
33
|
+
* @param connection The Solana connection
|
|
34
|
+
*/
|
|
35
|
+
static load(connection: web3.Connection): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Get pool info from Raydium API v3
|
|
38
|
+
*
|
|
39
|
+
* @param poolId The pool id to get the pool info from.
|
|
40
|
+
* @returns The pool info.
|
|
41
|
+
*/
|
|
42
|
+
getPoolInfoFromRpc(poolId: web3.PublicKey): Promise<ApiV3PoolInfoConcentratedItem>;
|
|
43
|
+
getLiquidityFromAmounts(connection: web3.Connection, poolId: web3.PublicKey, amountA: BN, amountB: BN, tickLower: number, tickUpper: number, slippage: number, add: boolean): Promise<{
|
|
44
|
+
liquidity: BN;
|
|
45
|
+
amount0Max: BN;
|
|
46
|
+
amount1Max: BN;
|
|
47
|
+
}>;
|
|
48
|
+
getAmountsFromLiquidity(connection: web3.Connection, poolId: web3.PublicKey, liquidity: BN, tickLower: number, tickUpper: number, slippage: number, add: boolean): Promise<{
|
|
49
|
+
amount0Min: BN;
|
|
50
|
+
amount1Min: BN;
|
|
51
|
+
amountA: import("@raydium-io/raydium-sdk-v2").GetTransferAmountFee;
|
|
52
|
+
amountB: import("@raydium-io/raydium-sdk-v2").GetTransferAmountFee;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Load the Raydium SDK
|
|
57
|
+
*
|
|
58
|
+
* @param connection The Solana connection
|
|
59
|
+
*/
|
|
60
|
+
export declare function load(connection: web3.Connection): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Get the Raydium SDK instance
|
|
63
|
+
*
|
|
64
|
+
* @returns The Raydium SDK instance
|
|
65
|
+
*/
|
|
66
|
+
export declare function raydium(): Raydium;
|
|
67
|
+
//# sourceMappingURL=RaydiumSDK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RaydiumSDK.d.ts","sourceRoot":"","sources":["../../src/classes/RaydiumSDK.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,EACL,OAAO,EACP,6BAA6B,EAG9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB;;;;GAIG;AACH,qBAAa,UAAU;IAErB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS,CAAa;IAErC;;OAEG;IACI,GAAG,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,OAAO;IAIP;;;;OAIG;IACH,MAAM,CAAC,QAAQ,IAAI,UAAU;IAI7B;;;;OAIG;WACU,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU;IAiB7C;;;;;OAKG;IACG,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAmDlF,uBAAuB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO;;;;;IAsD3K,uBAAuB,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO;;;;;;CAkDvK;AAED;;;;GAIG;AACH,wBAAsB,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,iBAErD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,YAEtB"}
|
|
@@ -0,0 +1,206 @@
|
|
|
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.RaydiumSDK = void 0;
|
|
13
|
+
exports.load = load;
|
|
14
|
+
exports.raydium = raydium;
|
|
15
|
+
const raydium_sdk_v2_1 = require("@raydium-io/raydium-sdk-v2");
|
|
16
|
+
const functions_1 = require("../functions");
|
|
17
|
+
/**
|
|
18
|
+
* Raydium SDK class
|
|
19
|
+
*
|
|
20
|
+
* This class is used to load the Raydium SDK and get the instance
|
|
21
|
+
*/
|
|
22
|
+
class RaydiumSDK {
|
|
23
|
+
/**
|
|
24
|
+
* Constructor
|
|
25
|
+
*
|
|
26
|
+
* @param sdk The Raydium SDK instance
|
|
27
|
+
*/
|
|
28
|
+
constructor(sdk) {
|
|
29
|
+
this.sdk = sdk;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the instance of the Raydium SDK
|
|
33
|
+
*
|
|
34
|
+
* @returns The Raydium SDK instance
|
|
35
|
+
*/
|
|
36
|
+
static instance() {
|
|
37
|
+
return this._instance;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Load the Raydium SDK
|
|
41
|
+
*
|
|
42
|
+
* @param connection The Solana connection
|
|
43
|
+
*/
|
|
44
|
+
static load(connection) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
// Load the SDK only once
|
|
47
|
+
if (RaydiumSDK._instance) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Load the SDK
|
|
51
|
+
const sdk = yield raydium_sdk_v2_1.Raydium.load({
|
|
52
|
+
connection,
|
|
53
|
+
disableLoadToken: false,
|
|
54
|
+
});
|
|
55
|
+
// Set the instance
|
|
56
|
+
RaydiumSDK._instance = new RaydiumSDK(sdk);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get pool info from Raydium API v3
|
|
61
|
+
*
|
|
62
|
+
* @param poolId The pool id to get the pool info from.
|
|
63
|
+
* @returns The pool info.
|
|
64
|
+
*/
|
|
65
|
+
getPoolInfoFromRpc(poolId) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const _poolInfo = yield fetch(`https://api-v3.raydium.io/pools/info/ids?ids=${poolId.toString()}`, {
|
|
68
|
+
method: 'GET',
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const data = yield _poolInfo.json();
|
|
74
|
+
const poolInfo = data.data[0];
|
|
75
|
+
const result = {
|
|
76
|
+
type: "Concentrated",
|
|
77
|
+
programId: poolInfo.programId,
|
|
78
|
+
id: poolInfo.id,
|
|
79
|
+
mintA: poolInfo.mintA,
|
|
80
|
+
mintB: poolInfo.mintB,
|
|
81
|
+
rewardDefaultInfos: poolInfo.rewardDefaultInfos,
|
|
82
|
+
rewardDefaultPoolInfos: poolInfo.rewardDefaultPoolInfos,
|
|
83
|
+
price: poolInfo.price,
|
|
84
|
+
mintAmountA: poolInfo.mintAmountA,
|
|
85
|
+
mintAmountB: poolInfo.mintAmountB,
|
|
86
|
+
feeRate: poolInfo.feeRate,
|
|
87
|
+
openTime: poolInfo.openTime,
|
|
88
|
+
tvl: poolInfo.tvl,
|
|
89
|
+
day: poolInfo.day,
|
|
90
|
+
week: poolInfo.week,
|
|
91
|
+
month: poolInfo.month,
|
|
92
|
+
pooltype: poolInfo.pooltype,
|
|
93
|
+
farmUpcomingCount: poolInfo.farmUpcomingCount,
|
|
94
|
+
farmOngoingCount: poolInfo.farmOngoingCount,
|
|
95
|
+
farmFinishedCount: poolInfo.farmFinishedCount,
|
|
96
|
+
burnPercent: poolInfo.burnPercent,
|
|
97
|
+
config: {
|
|
98
|
+
id: poolInfo.config.id,
|
|
99
|
+
index: poolInfo.config.index,
|
|
100
|
+
protocolFeeRate: poolInfo.config.protocolFeeRate,
|
|
101
|
+
tradeFeeRate: poolInfo.config.tradeFeeRate,
|
|
102
|
+
tickSpacing: poolInfo.config.tickSpacing,
|
|
103
|
+
fundFeeRate: poolInfo.config.fundFeeRate,
|
|
104
|
+
description: poolInfo.config.description,
|
|
105
|
+
defaultRange: poolInfo.config.defaultRange,
|
|
106
|
+
defaultRangePoint: poolInfo.config.defaultRangePoint,
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return result;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
getLiquidityFromAmounts(connection, poolId, amountA, amountB, tickLower, tickUpper, slippage, add) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
// Load the Raydium SDK
|
|
115
|
+
yield RaydiumSDK.load(connection);
|
|
116
|
+
// Benchmark the getPoolInfoFromRpc function
|
|
117
|
+
(0, functions_1.benchmark)({ name: `getLiquidityFromAmounts`, msg: `getPoolInfoFromRpc` });
|
|
118
|
+
// Get the pool info
|
|
119
|
+
let poolInfo = yield RaydiumSDK.instance().getPoolInfoFromRpc(poolId);
|
|
120
|
+
// Benchmark the getPoolInfoFromRpc function (end)
|
|
121
|
+
(0, functions_1.benchmark)({ name: `getLiquidityFromAmounts`, msg: `getPoolInfoFromRpc`, end: true });
|
|
122
|
+
// Benchmark the getEpochInfo function
|
|
123
|
+
(0, functions_1.benchmark)({ name: `getLiquidityFromAmounts`, msg: `getEpochInfo` });
|
|
124
|
+
// Get the epoch info
|
|
125
|
+
let epochInfo = yield connection.getEpochInfo();
|
|
126
|
+
// Benchmark the getEpochInfo function (end)
|
|
127
|
+
(0, functions_1.benchmark)({ name: `getLiquidityFromAmounts`, msg: `getEpochInfo`, end: true });
|
|
128
|
+
// Benchmark the getLiquidityFromAmounts function
|
|
129
|
+
(0, functions_1.benchmark)({ name: `getLiquidityFromAmounts`, msg: `getLiquidityFromAmounts` });
|
|
130
|
+
const { liquidity, amountSlippageA, amountSlippageB, amountA: _amountA, amountB: _amountB, } = (0, raydium_sdk_v2_1.getLiquidityFromAmounts)({
|
|
131
|
+
poolInfo,
|
|
132
|
+
tickLower,
|
|
133
|
+
tickUpper,
|
|
134
|
+
amountA,
|
|
135
|
+
amountB,
|
|
136
|
+
slippage,
|
|
137
|
+
add: true,
|
|
138
|
+
epochInfo,
|
|
139
|
+
amountHasFee: false,
|
|
140
|
+
});
|
|
141
|
+
// Benchmark the getLiquidityFromAmounts function (end)
|
|
142
|
+
(0, functions_1.benchmark)({ name: `getLiquidityFromAmounts`, msg: `getLiquidityFromAmounts`, end: true });
|
|
143
|
+
return {
|
|
144
|
+
liquidity,
|
|
145
|
+
amount0Max: amountSlippageA.amount,
|
|
146
|
+
amount1Max: amountSlippageB.amount,
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
getAmountsFromLiquidity(connection, poolId, liquidity, tickLower, tickUpper, slippage, add) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
// Load the Raydium SDK
|
|
153
|
+
yield RaydiumSDK.load(connection);
|
|
154
|
+
// Benchmark the getPoolInfoFromRpc function
|
|
155
|
+
(0, functions_1.benchmark)({ name: `getAmountsFromLiquidity`, msg: `getPoolInfoFromRpc` });
|
|
156
|
+
// Get the pool info
|
|
157
|
+
let poolInfo = yield RaydiumSDK.instance().getPoolInfoFromRpc(poolId);
|
|
158
|
+
(0, functions_1.benchmark)({ name: `getAmountsFromLiquidity`, msg: `getPoolInfoFromRpc`, end: true });
|
|
159
|
+
// Benchmark the getEpochInfo function
|
|
160
|
+
(0, functions_1.benchmark)({ name: `getAmountsFromLiquidity`, msg: `getEpochInfo` });
|
|
161
|
+
// Get the epoch info
|
|
162
|
+
let epochInfo = yield connection.getEpochInfo();
|
|
163
|
+
// Benchmark the getEpochInfo function (end)
|
|
164
|
+
(0, functions_1.benchmark)({ name: `getAmountsFromLiquidity`, msg: `getEpochInfo`, end: true });
|
|
165
|
+
// Benchmark the getAmountsFromLiquidity function
|
|
166
|
+
(0, functions_1.benchmark)({ name: `getAmountsFromLiquidity`, msg: `getAmountsFromLiquidity` });
|
|
167
|
+
// Get the amounts from liquidity
|
|
168
|
+
const { amountSlippageA, amountSlippageB, amountA, amountB, } = yield raydium_sdk_v2_1.PoolUtils.getAmountsFromLiquidity({
|
|
169
|
+
epochInfo,
|
|
170
|
+
poolInfo,
|
|
171
|
+
tickLower,
|
|
172
|
+
tickUpper,
|
|
173
|
+
liquidity,
|
|
174
|
+
slippage,
|
|
175
|
+
add,
|
|
176
|
+
});
|
|
177
|
+
// Benchmark the getAmountsFromLiquidity function (end)
|
|
178
|
+
(0, functions_1.benchmark)({ name: `getAmountsFromLiquidity`, msg: `getAmountsFromLiquidity`, end: true });
|
|
179
|
+
return {
|
|
180
|
+
amount0Min: amountSlippageA.amount,
|
|
181
|
+
amount1Min: amountSlippageB.amount,
|
|
182
|
+
amountA,
|
|
183
|
+
amountB,
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.RaydiumSDK = RaydiumSDK;
|
|
189
|
+
/**
|
|
190
|
+
* Load the Raydium SDK
|
|
191
|
+
*
|
|
192
|
+
* @param connection The Solana connection
|
|
193
|
+
*/
|
|
194
|
+
function load(connection) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
yield RaydiumSDK.load(connection);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get the Raydium SDK instance
|
|
201
|
+
*
|
|
202
|
+
* @returns The Raydium SDK instance
|
|
203
|
+
*/
|
|
204
|
+
function raydium() {
|
|
205
|
+
return RaydiumSDK.instance().sdk;
|
|
206
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Token, LoadFromPersistenceFn, StoreToPersistenceFn } from "../types";
|
|
2
|
+
export declare class Search {
|
|
3
|
+
protected readonly url: string;
|
|
4
|
+
private tokenIndices?;
|
|
5
|
+
private tokens?;
|
|
6
|
+
private _loaded;
|
|
7
|
+
private _loadedFromPersistence;
|
|
8
|
+
private previousHash;
|
|
9
|
+
private latestHash;
|
|
10
|
+
disableFetch: boolean;
|
|
11
|
+
private loadFromPersistenceFn?;
|
|
12
|
+
private storeToPersistenceFn?;
|
|
13
|
+
/**
|
|
14
|
+
* Set load persistence callback
|
|
15
|
+
*
|
|
16
|
+
* @param loadFromPersistenceFn
|
|
17
|
+
*/
|
|
18
|
+
setLoadFromPersistenceFn(loadFromPersistenceFn: LoadFromPersistenceFn): void;
|
|
19
|
+
/**
|
|
20
|
+
* Set store to persistence callback
|
|
21
|
+
*
|
|
22
|
+
* @param storeToPersistenceFn
|
|
23
|
+
*/
|
|
24
|
+
setStoreToPersistenceFn(storeToPersistenceFn: StoreToPersistenceFn): void;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the token indices and tokens have been loaded.
|
|
27
|
+
*
|
|
28
|
+
* @returns {boolean} True if the token indices and tokens have been loaded, false otherwise.
|
|
29
|
+
*/
|
|
30
|
+
get loaded(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Constructs a new instance of the Search class.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} url - The base URL for the API.
|
|
35
|
+
*/
|
|
36
|
+
constructor(url: string);
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves tokens that match the given keyword.
|
|
39
|
+
*
|
|
40
|
+
* This method searches for tokens that match the provided keyword.
|
|
41
|
+
* If the token indices or tokens are not yet loaded, it logs a warning and returns an empty array.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} keyword - The keyword to search for.
|
|
44
|
+
* @param {number} limit - Number of results to show.
|
|
45
|
+
* @param {boolean} noLimit - disable limit
|
|
46
|
+
* @returns {Token[]} An array of tokens that match the given keyword.
|
|
47
|
+
*/
|
|
48
|
+
token(keyword: string, limit?: number, noLimit?: boolean): Token[];
|
|
49
|
+
/**
|
|
50
|
+
* Loads the token indices and tokens.
|
|
51
|
+
*
|
|
52
|
+
* This method loads the token indices and tokens if they are not already loaded.
|
|
53
|
+
* It also sets up a periodic update to refresh the token indices and tokens every minute.
|
|
54
|
+
*
|
|
55
|
+
* @returns {Promise<void>} A promise that resolves when the initial load is complete.
|
|
56
|
+
*/
|
|
57
|
+
load(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Load tokens and indices from persistence
|
|
60
|
+
*
|
|
61
|
+
* @param tokenIndices
|
|
62
|
+
* @param tokens
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
private loadFromPersistence;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves and updates the token indices and tokens if necessary.
|
|
68
|
+
*
|
|
69
|
+
* This method checks if the current token indices and tokens are undefined.
|
|
70
|
+
* If they are, it fetches the token indices and tokens from the API.
|
|
71
|
+
* It then compares the hash of the current token indices with the hash from the server.
|
|
72
|
+
* If the hashes do not match, it updates the token indices and tokens.
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
* @returns {Promise<void>} A promise that resolves when the token indices and tokens are updated.
|
|
76
|
+
*/
|
|
77
|
+
private getTokenIndices;
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves all tokens from the API.
|
|
80
|
+
*
|
|
81
|
+
* This method makes a GET request to the API to fetch all tokens.
|
|
82
|
+
*
|
|
83
|
+
* @private
|
|
84
|
+
* @returns {Promise<Token[]>} A promise that resolves to an array of tokens.
|
|
85
|
+
*/
|
|
86
|
+
private getAllTokens;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves the search indices from the API based on the provided key and optional hash.
|
|
89
|
+
*
|
|
90
|
+
* This method makes a GET request to the API to fetch the search indices for the specified key.
|
|
91
|
+
* If a hash is provided, it includes the hash in the request to check for updated indices.
|
|
92
|
+
*
|
|
93
|
+
* @private
|
|
94
|
+
* @param {string} key - The key to identify the search indices.
|
|
95
|
+
* @param {string} [hash] - Optional hash to validate against the current hash of the indices.
|
|
96
|
+
* @returns {Promise<SearchIndices>} A promise that resolves to the search indices for the specified key.
|
|
97
|
+
*/
|
|
98
|
+
private getSearchIndices;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=Search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Search.d.ts","sourceRoot":"","sources":["../../src/classes/Search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG7F,qBAAa,MAAM;IA4Cf,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM;IA1ChC,OAAO,CAAC,YAAY,CAAC,CAAgB;IACrC,OAAO,CAAC,MAAM,CAAC,CAAU;IACzB,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,UAAU,CAAc;IAChC,YAAY,EAAE,OAAO,CAAS;IAE9B,OAAO,CAAC,qBAAqB,CAAC,CAAwB;IACtD,OAAO,CAAC,oBAAoB,CAAC,CAAuB;IAEpD;;;;OAIG;IACH,wBAAwB,CAAC,qBAAqB,EAAE,qBAAqB;IAIrE;;;;OAIG;IACH,uBAAuB,CAAC,oBAAoB,EAAE,oBAAoB;IAIlE;;;;OAIG;IACH,IAAI,MAAM,IAAI,OAAO,CAAwB;IAE7C;;;;OAIG;gBAEkB,GAAG,EAAE,MAAM;IAGhC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,MAAY,EAAE,OAAO,GAAE,OAAe,GAAG,KAAK,EAAE;IAiB9E;;;;;;;OAOG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsC3B;;;;;;OAMG;YACW,mBAAmB;IAWjC;;;;;;;;;;OAUG;YACW,eAAe;IAmB7B;;;;;;;OAOG;YACW,YAAY;IAI1B;;;;;;;;;;OAUG;YACW,gBAAgB;CAO/B"}
|