@clonegod/ttd-sol-common 1.0.12 → 1.0.14
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/helius_sdk_v1.4.0/Helius.d.ts +31 -0
- package/dist/helius_sdk_v1.4.0/Helius.js +455 -0
- package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +50 -0
- package/dist/helius_sdk_v1.4.0/RpcClient.js +639 -0
- package/dist/helius_sdk_v1.4.0/constants.d.ts +1 -0
- package/dist/helius_sdk_v1.4.0/constants.js +4 -0
- package/dist/helius_sdk_v1.4.0/index.d.ts +5 -0
- package/dist/helius_sdk_v1.4.0/index.js +21 -0
- package/dist/helius_sdk_v1.4.0/types/das-types.d.ts +408 -0
- package/dist/helius_sdk_v1.4.0/types/das-types.js +2 -0
- package/dist/helius_sdk_v1.4.0/types/enums.d.ts +542 -0
- package/dist/helius_sdk_v1.4.0/types/enums.js +605 -0
- package/dist/helius_sdk_v1.4.0/types/index.d.ts +3 -0
- package/dist/helius_sdk_v1.4.0/types/index.js +19 -0
- package/dist/helius_sdk_v1.4.0/types/types.d.ts +305 -0
- package/dist/helius_sdk_v1.4.0/types/types.js +2 -0
- package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.d.ts +2 -0
- package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.js +20 -0
- package/dist/helius_sdk_v1.4.0/utils/index.d.ts +1 -0
- package/dist/helius_sdk_v1.4.0/utils/index.js +17 -0
- package/dist/helius_sdk_v1.4.0/utils/mintApi.d.ts +2 -0
- package/dist/helius_sdk_v1.4.0/utils/mintApi.js +15 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +76 -2
- package/package.json +1 -1
|
@@ -0,0 +1,639 @@
|
|
|
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.RpcClient = void 0;
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const types_1 = require("./types");
|
|
20
|
+
class RpcClient {
|
|
21
|
+
constructor(connection, id) {
|
|
22
|
+
this.connection = connection;
|
|
23
|
+
this.id = id;
|
|
24
|
+
}
|
|
25
|
+
airdrop(publicKey, lamports, commitment) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const signature = yield this.connection.requestAirdrop(publicKey, lamports);
|
|
28
|
+
const blockhashWithExpiryBlockHeight = yield this.getLatestBlockhash();
|
|
29
|
+
const confirmResponse = yield this.connection.confirmTransaction(Object.assign({ signature }, blockhashWithExpiryBlockHeight), commitment);
|
|
30
|
+
return Object.assign({ signature, confirmResponse }, blockhashWithExpiryBlockHeight);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getLatestBlockhash() {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* (commitmentOrConfig = 'finalized') {
|
|
35
|
+
return this.connection.getLatestBlockhash(commitmentOrConfig);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getCurrentTPS() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
try {
|
|
42
|
+
const samples = yield this.connection.getRecentPerformanceSamples(1);
|
|
43
|
+
return ((_a = samples[0]) === null || _a === void 0 ? void 0 : _a.numTransactions) / ((_b = samples[0]) === null || _b === void 0 ? void 0 : _b.samplePeriodSecs);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw new Error(`error calling getCurrentTPS: ${e}`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
getStakeAccounts(wallet) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
return this.connection.getParsedProgramAccounts(new web3_js_1.PublicKey('Stake11111111111111111111111111111111111111'), {
|
|
54
|
+
filters: [
|
|
55
|
+
{
|
|
56
|
+
dataSize: 200,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
memcmp: {
|
|
60
|
+
offset: 44,
|
|
61
|
+
bytes: wallet,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
throw new Error(`error calling getStakeAccounts: ${e}`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
getTokenHolders(mintAddress) {
|
|
73
|
+
try {
|
|
74
|
+
return this.connection.getParsedProgramAccounts(new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), {
|
|
75
|
+
filters: [
|
|
76
|
+
{
|
|
77
|
+
dataSize: 165,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
memcmp: {
|
|
81
|
+
offset: 0,
|
|
82
|
+
bytes: mintAddress,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
throw new Error(`error calling getTokenHolders: ${e}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
getAsset(params) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
96
|
+
const response = yield axios_1.default.post(url, {
|
|
97
|
+
jsonrpc: '2.0',
|
|
98
|
+
id: this.id,
|
|
99
|
+
method: 'getAsset',
|
|
100
|
+
params,
|
|
101
|
+
}, {
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/json',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const { result } = response.data;
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new Error(`Error in getAsset: ${error}`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
getRwaAsset(params) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
try {
|
|
117
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
118
|
+
const response = yield axios_1.default.post(url, {
|
|
119
|
+
jsonrpc: '2.0',
|
|
120
|
+
id: this.id,
|
|
121
|
+
method: 'getRwaAccountsByMint',
|
|
122
|
+
params,
|
|
123
|
+
}, {
|
|
124
|
+
headers: {
|
|
125
|
+
'Content-Type': 'application/json',
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
const { result } = response.data;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw new Error(`Error in getRwaAsset: ${error}`);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
getAssetBatch(params) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
try {
|
|
139
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
140
|
+
const response = yield axios_1.default.post(url, {
|
|
141
|
+
jsonrpc: '2.0',
|
|
142
|
+
id: this.id,
|
|
143
|
+
method: 'getAssetBatch',
|
|
144
|
+
params,
|
|
145
|
+
});
|
|
146
|
+
return response.data.result;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
throw new Error(`Error in getAssetBatch: ${error}`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
getAssetProof(params) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
try {
|
|
156
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
157
|
+
const response = yield axios_1.default.post(url, {
|
|
158
|
+
jsonrpc: '2.0',
|
|
159
|
+
id: this.id,
|
|
160
|
+
method: 'getAssetProof',
|
|
161
|
+
params,
|
|
162
|
+
});
|
|
163
|
+
const { data } = response;
|
|
164
|
+
return data.result;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
throw new Error(`Error in getAssetProof: ${error}`);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
getAssetsByGroup(params) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
try {
|
|
174
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
175
|
+
const response = yield axios_1.default.post(url, {
|
|
176
|
+
jsonrpc: '2.0',
|
|
177
|
+
id: this.id,
|
|
178
|
+
method: 'getAssetsByGroup',
|
|
179
|
+
params,
|
|
180
|
+
});
|
|
181
|
+
const { data } = response;
|
|
182
|
+
return data.result;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw new Error(`Error in getAssetsByGroup: ${error}`);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
getAssetsByOwner(params) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
try {
|
|
192
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
193
|
+
const response = yield axios_1.default.post(url, {
|
|
194
|
+
jsonrpc: '2.0',
|
|
195
|
+
id: this.id,
|
|
196
|
+
method: 'getAssetsByOwner',
|
|
197
|
+
params,
|
|
198
|
+
});
|
|
199
|
+
const { data } = response;
|
|
200
|
+
return data.result;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
throw new Error(`Error in getAssetsByOwner: ${error}`);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
getAssetsByCreator(params) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
try {
|
|
210
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
211
|
+
const response = yield axios_1.default.post(url, {
|
|
212
|
+
jsonrpc: '2.0',
|
|
213
|
+
id: this.id,
|
|
214
|
+
method: 'getAssetsByCreator',
|
|
215
|
+
params,
|
|
216
|
+
});
|
|
217
|
+
const { data } = response;
|
|
218
|
+
return data.result;
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
throw new Error(`Error in getAssetsByCreator: ${error}`);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
getAssetsByAuthority(params) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
try {
|
|
228
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
229
|
+
const response = yield axios_1.default.post(url, {
|
|
230
|
+
jsonrpc: '2.0',
|
|
231
|
+
id: this.id,
|
|
232
|
+
method: 'getAssetsByAuthority',
|
|
233
|
+
params,
|
|
234
|
+
});
|
|
235
|
+
const { data } = response;
|
|
236
|
+
return data.result;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
throw new Error(`Error in getAssetsByAuthority: ${error}`);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
searchAssets(params) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
try {
|
|
246
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
247
|
+
const response = yield axios_1.default.post(url, {
|
|
248
|
+
jsonrpc: '2.0',
|
|
249
|
+
id: this.id,
|
|
250
|
+
method: 'searchAssets',
|
|
251
|
+
params,
|
|
252
|
+
});
|
|
253
|
+
const { data } = response;
|
|
254
|
+
return data.result;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
throw new Error(`Error in searchAssets: ${error}`);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
getSignaturesForAsset(params) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
try {
|
|
264
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
265
|
+
const response = yield axios_1.default.post(url, {
|
|
266
|
+
jsonrpc: '2.0',
|
|
267
|
+
id: this.id,
|
|
268
|
+
method: 'getSignaturesForAsset',
|
|
269
|
+
params,
|
|
270
|
+
});
|
|
271
|
+
const { data } = response;
|
|
272
|
+
return data.result;
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
throw new Error(`Error in getSignaturesForAsset: ${error}`);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
getPriorityFeeEstimate(params) {
|
|
280
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
281
|
+
try {
|
|
282
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
283
|
+
const response = yield axios_1.default.post(url, {
|
|
284
|
+
jsonrpc: '2.0',
|
|
285
|
+
id: this.id,
|
|
286
|
+
method: 'getPriorityFeeEstimate',
|
|
287
|
+
params: [params],
|
|
288
|
+
}, {
|
|
289
|
+
headers: { 'Content-Type': 'application/json' },
|
|
290
|
+
});
|
|
291
|
+
if (response.data.error) {
|
|
292
|
+
throw new Error(`Error fetching priority fee estimate: ${JSON.stringify(response.data.error, null, 2)}`);
|
|
293
|
+
}
|
|
294
|
+
return response.data.result;
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
298
|
+
throw new Error(`Error fetching priority fee estimate: ${JSON.stringify(error.response.data, null, 2)}`);
|
|
299
|
+
}
|
|
300
|
+
throw new Error(`Error fetching priority fee estimate: ${error}`);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
getComputeUnits(instructions, payer, lookupTables, signers) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
const testInstructions = [
|
|
307
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 1400000 }),
|
|
308
|
+
...instructions,
|
|
309
|
+
];
|
|
310
|
+
const testTransaction = new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
311
|
+
instructions: testInstructions,
|
|
312
|
+
payerKey: payer,
|
|
313
|
+
recentBlockhash: (yield this.connection.getLatestBlockhash()).blockhash,
|
|
314
|
+
}).compileToV0Message(lookupTables));
|
|
315
|
+
if (signers) {
|
|
316
|
+
testTransaction.sign(signers);
|
|
317
|
+
}
|
|
318
|
+
const rpcResponse = yield this.connection.simulateTransaction(testTransaction, {
|
|
319
|
+
sigVerify: !!signers,
|
|
320
|
+
});
|
|
321
|
+
if (rpcResponse.value.err) {
|
|
322
|
+
console.error(`Simulation error: ${JSON.stringify(rpcResponse.value.err, null, 2)}`);
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
return rpcResponse.value.unitsConsumed || null;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
pollTransactionConfirmation(txtSig_1) {
|
|
329
|
+
return __awaiter(this, arguments, void 0, function* (txtSig, pollOptions = {
|
|
330
|
+
confirmationStatuses: ["confirmed", "finalized"],
|
|
331
|
+
timeout: 15000,
|
|
332
|
+
interval: 5000
|
|
333
|
+
}) {
|
|
334
|
+
let elapsed = 0;
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
const intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
var _a, _b, _c;
|
|
338
|
+
elapsed += pollOptions.interval;
|
|
339
|
+
if (elapsed >= pollOptions.timeout) {
|
|
340
|
+
clearInterval(intervalId);
|
|
341
|
+
reject(new Error(`Transaction ${txtSig}'s confirmation timed out`));
|
|
342
|
+
}
|
|
343
|
+
const status = yield this.connection.getSignatureStatus(txtSig);
|
|
344
|
+
if (((_a = status === null || status === void 0 ? void 0 : status.value) === null || _a === void 0 ? void 0 : _a.confirmationStatus) && ((_b = pollOptions.confirmationStatuses) === null || _b === void 0 ? void 0 : _b.includes((_c = status === null || status === void 0 ? void 0 : status.value) === null || _c === void 0 ? void 0 : _c.confirmationStatus))) {
|
|
345
|
+
clearInterval(intervalId);
|
|
346
|
+
resolve(txtSig);
|
|
347
|
+
}
|
|
348
|
+
}), pollOptions.interval);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
createSmartTransaction(instructions_1, signers_1) {
|
|
353
|
+
return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], feePayer, serializeOptions = {
|
|
354
|
+
requireAllSignatures: true,
|
|
355
|
+
verifySignatures: true,
|
|
356
|
+
}) {
|
|
357
|
+
if (!signers.length) {
|
|
358
|
+
throw new Error('The transaction must have at least one signer');
|
|
359
|
+
}
|
|
360
|
+
const existingComputeBudgetInstructions = instructions.filter((instruction) => instruction.programId.equals(web3_js_1.ComputeBudgetProgram.programId));
|
|
361
|
+
if (existingComputeBudgetInstructions.length > 0) {
|
|
362
|
+
throw new Error('Cannot provide instructions that set the compute unit price and/or limit');
|
|
363
|
+
}
|
|
364
|
+
const payerKey = feePayer ? feePayer.publicKey : signers[0].publicKey;
|
|
365
|
+
const { context: { slot: minContextSlot }, value: blockhash, } = yield this.connection.getLatestBlockhashAndContext();
|
|
366
|
+
const recentBlockhash = blockhash.blockhash;
|
|
367
|
+
const isVersioned = lookupTables.length > 0;
|
|
368
|
+
let legacyTransaction = null;
|
|
369
|
+
let versionedTransaction = null;
|
|
370
|
+
if (isVersioned) {
|
|
371
|
+
const v0Message = new web3_js_1.TransactionMessage({
|
|
372
|
+
instructions,
|
|
373
|
+
payerKey,
|
|
374
|
+
recentBlockhash,
|
|
375
|
+
}).compileToV0Message(lookupTables);
|
|
376
|
+
versionedTransaction = new web3_js_1.VersionedTransaction(v0Message);
|
|
377
|
+
const allSigners = feePayer ? [...signers, feePayer] : signers;
|
|
378
|
+
versionedTransaction.sign(allSigners);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
legacyTransaction = new web3_js_1.Transaction().add(...instructions);
|
|
382
|
+
legacyTransaction.recentBlockhash = recentBlockhash;
|
|
383
|
+
legacyTransaction.feePayer = payerKey;
|
|
384
|
+
for (const signer of signers) {
|
|
385
|
+
legacyTransaction.partialSign(signer);
|
|
386
|
+
}
|
|
387
|
+
if (feePayer) {
|
|
388
|
+
legacyTransaction.partialSign(feePayer);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const serializedTransaction = bs58_1.default.encode(isVersioned
|
|
392
|
+
? versionedTransaction.serialize()
|
|
393
|
+
: legacyTransaction.serialize(serializeOptions));
|
|
394
|
+
const priorityFeeEstimateResponse = yield this.getPriorityFeeEstimate({
|
|
395
|
+
transaction: serializedTransaction,
|
|
396
|
+
options: {
|
|
397
|
+
recommended: true,
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
const { priorityFeeEstimate } = priorityFeeEstimateResponse;
|
|
401
|
+
if (!priorityFeeEstimate) {
|
|
402
|
+
throw new Error('Priority fee estimate not available');
|
|
403
|
+
}
|
|
404
|
+
const computeBudgetIx = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
405
|
+
microLamports: priorityFeeEstimate,
|
|
406
|
+
});
|
|
407
|
+
instructions.unshift(computeBudgetIx);
|
|
408
|
+
const units = yield this.getComputeUnits(instructions, payerKey, isVersioned ? lookupTables : [], signers);
|
|
409
|
+
if (!units) {
|
|
410
|
+
throw new Error(`Error fetching compute units for the instructions provided`);
|
|
411
|
+
}
|
|
412
|
+
const customersCU = units < 1000 ? 1000 : Math.ceil(units * 1.1);
|
|
413
|
+
const computeUnitsIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
414
|
+
units: customersCU,
|
|
415
|
+
});
|
|
416
|
+
instructions.unshift(computeUnitsIx);
|
|
417
|
+
if (isVersioned) {
|
|
418
|
+
const v0Message = new web3_js_1.TransactionMessage({
|
|
419
|
+
instructions,
|
|
420
|
+
payerKey,
|
|
421
|
+
recentBlockhash,
|
|
422
|
+
}).compileToV0Message(lookupTables);
|
|
423
|
+
versionedTransaction = new web3_js_1.VersionedTransaction(v0Message);
|
|
424
|
+
const allSigners = feePayer ? [...signers, feePayer] : signers;
|
|
425
|
+
versionedTransaction.sign(allSigners);
|
|
426
|
+
return {
|
|
427
|
+
transaction: versionedTransaction,
|
|
428
|
+
blockhash,
|
|
429
|
+
minContextSlot,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
legacyTransaction = new web3_js_1.Transaction().add(...instructions);
|
|
433
|
+
legacyTransaction.recentBlockhash = recentBlockhash;
|
|
434
|
+
legacyTransaction.feePayer = payerKey;
|
|
435
|
+
for (const signer of signers) {
|
|
436
|
+
legacyTransaction.partialSign(signer);
|
|
437
|
+
}
|
|
438
|
+
if (feePayer) {
|
|
439
|
+
legacyTransaction.partialSign(feePayer);
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
transaction: legacyTransaction,
|
|
443
|
+
blockhash,
|
|
444
|
+
minContextSlot,
|
|
445
|
+
};
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
sendSmartTransaction(instructions_1, signers_1) {
|
|
449
|
+
return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], sendOptions = { skipPreflight: false, lastValidBlockHeightOffset: 150 }) {
|
|
450
|
+
var _a;
|
|
451
|
+
const lastValidBlockHeightOffset = (_a = sendOptions.lastValidBlockHeightOffset) !== null && _a !== void 0 ? _a : 150;
|
|
452
|
+
if (lastValidBlockHeightOffset < 0)
|
|
453
|
+
throw new Error('expiryBlockOffset must be a positive integer');
|
|
454
|
+
try {
|
|
455
|
+
const { transaction, blockhash, minContextSlot } = yield this.createSmartTransaction(instructions, signers, lookupTables, sendOptions.feePayer);
|
|
456
|
+
const commitment = (sendOptions === null || sendOptions === void 0 ? void 0 : sendOptions.preflightCommitment) || 'confirmed';
|
|
457
|
+
const currentBlockHeight = yield this.connection.getBlockHeight();
|
|
458
|
+
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
459
|
+
let error;
|
|
460
|
+
do {
|
|
461
|
+
try {
|
|
462
|
+
const signature = yield this.connection.sendRawTransaction(transaction.serialize(), Object.assign({ maxRetries: 0, preflightCommitment: 'confirmed', skipPreflight: sendOptions.skipPreflight, minContextSlot }, sendOptions));
|
|
463
|
+
const abortSignal = AbortSignal.timeout(15000);
|
|
464
|
+
yield this.connection.confirmTransaction({
|
|
465
|
+
abortSignal,
|
|
466
|
+
signature,
|
|
467
|
+
blockhash: blockhash.blockhash,
|
|
468
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
|
469
|
+
}, commitment);
|
|
470
|
+
abortSignal.removeEventListener('abort', () => { });
|
|
471
|
+
return signature;
|
|
472
|
+
}
|
|
473
|
+
catch (_error) {
|
|
474
|
+
if (!(_error instanceof Error))
|
|
475
|
+
error = new Error();
|
|
476
|
+
error = _error;
|
|
477
|
+
}
|
|
478
|
+
} while (!(error instanceof web3_js_1.TransactionExpiredBlockheightExceededError));
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
throw new Error(`Error sending smart transaction: ${error}`);
|
|
482
|
+
}
|
|
483
|
+
throw new Error('Transaction failed to confirm within lastValidBlockHeight');
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
addTipInstruction(instructions, feePayer, tipAccount, tipAmount) {
|
|
487
|
+
const tipInstruction = web3_js_1.SystemProgram.transfer({
|
|
488
|
+
fromPubkey: feePayer,
|
|
489
|
+
toPubkey: new web3_js_1.PublicKey(tipAccount),
|
|
490
|
+
lamports: tipAmount,
|
|
491
|
+
});
|
|
492
|
+
instructions.push(tipInstruction);
|
|
493
|
+
}
|
|
494
|
+
createSmartTransactionWithTip(instructions_1, signers_1) {
|
|
495
|
+
return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], tipAmount = 1000, feePayer) {
|
|
496
|
+
if (!signers.length) {
|
|
497
|
+
throw new Error('The transaction must have at least one signer');
|
|
498
|
+
}
|
|
499
|
+
const randomTipAccount = types_1.JITO_TIP_ACCOUNTS[Math.floor(Math.random() * types_1.JITO_TIP_ACCOUNTS.length)];
|
|
500
|
+
const payerKey = feePayer ? feePayer.publicKey : signers[0].publicKey;
|
|
501
|
+
this.addTipInstruction(instructions, payerKey, randomTipAccount, tipAmount);
|
|
502
|
+
return this.createSmartTransaction(instructions, signers, lookupTables, feePayer);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
sendJitoBundle(serializedTransactions, jitoApiUrl) {
|
|
506
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
+
const response = yield axios_1.default.post(jitoApiUrl, {
|
|
508
|
+
jsonrpc: '2.0',
|
|
509
|
+
id: 1,
|
|
510
|
+
method: 'sendBundle',
|
|
511
|
+
params: [serializedTransactions],
|
|
512
|
+
}, {
|
|
513
|
+
headers: { 'Content-Type': 'application/json' },
|
|
514
|
+
});
|
|
515
|
+
if (response.data.error) {
|
|
516
|
+
throw new Error(`Error sending bundles: ${JSON.stringify(response.data.error, null, 2)}`);
|
|
517
|
+
}
|
|
518
|
+
return response.data.result;
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
getBundleStatuses(bundleIds, jitoApiUrl) {
|
|
522
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
+
const response = yield axios_1.default.post(jitoApiUrl, {
|
|
524
|
+
jsonrpc: '2.0',
|
|
525
|
+
id: 1,
|
|
526
|
+
method: 'getBundleStatuses',
|
|
527
|
+
params: [bundleIds],
|
|
528
|
+
}, {
|
|
529
|
+
headers: { 'Content-Type': 'application/json' },
|
|
530
|
+
});
|
|
531
|
+
if (response.data.error) {
|
|
532
|
+
throw new Error(`Error getting bundle statuses: ${JSON.stringify(response.data.error, null, 2)}`);
|
|
533
|
+
}
|
|
534
|
+
return response.data.result;
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
sendSmartTransactionWithTip(instructions_1, signers_1) {
|
|
538
|
+
return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], tipAmount = 1000, region = 'Default', feePayer, lastValidBlockHeightOffset = 150) {
|
|
539
|
+
if (lastValidBlockHeightOffset < 0)
|
|
540
|
+
throw new Error('lastValidBlockHeightOffset must be a positive integer');
|
|
541
|
+
if (!signers.length) {
|
|
542
|
+
throw new Error('The transaction must have at least one signer');
|
|
543
|
+
}
|
|
544
|
+
const { transaction, blockhash } = yield this.createSmartTransactionWithTip(instructions, signers, lookupTables, tipAmount, feePayer);
|
|
545
|
+
const serializedTransaction = bs58_1.default.encode(transaction.serialize());
|
|
546
|
+
const jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/bundles`;
|
|
547
|
+
const bundleId = yield this.sendJitoBundle([serializedTransaction], jitoApiUrl);
|
|
548
|
+
const currentBlockHeight = yield this.connection.getBlockHeight();
|
|
549
|
+
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
550
|
+
const timeout = 60000;
|
|
551
|
+
const interval = 5000;
|
|
552
|
+
const startTime = Date.now();
|
|
553
|
+
while (Date.now() - startTime < timeout ||
|
|
554
|
+
(yield this.connection.getBlockHeight()) <= lastValidBlockHeight) {
|
|
555
|
+
const bundleStatuses = yield this.getBundleStatuses([bundleId], jitoApiUrl);
|
|
556
|
+
if (bundleStatuses &&
|
|
557
|
+
bundleStatuses.value &&
|
|
558
|
+
bundleStatuses.value.length > 0) {
|
|
559
|
+
const status = bundleStatuses.value[0].confirmation_status;
|
|
560
|
+
if (status === 'confirmed') {
|
|
561
|
+
return bundleStatuses.value[0].transactions[0];
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
565
|
+
}
|
|
566
|
+
throw new Error('Bundle failed to confirm within the timeout period');
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
getNftEditions(params) {
|
|
570
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
571
|
+
try {
|
|
572
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
573
|
+
const response = yield axios_1.default.post(url, {
|
|
574
|
+
jsonrpc: '2.0',
|
|
575
|
+
id: this.id,
|
|
576
|
+
method: 'getNftEditions',
|
|
577
|
+
params,
|
|
578
|
+
}, {
|
|
579
|
+
headers: { 'Content-Type': 'application/json' },
|
|
580
|
+
});
|
|
581
|
+
return response.data.result;
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
throw new Error(`Error in getNftEditions: ${error}`);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
getTokenAccounts(params) {
|
|
589
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
590
|
+
try {
|
|
591
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
592
|
+
const response = yield axios_1.default.post(url, {
|
|
593
|
+
jsonrpc: '2.0',
|
|
594
|
+
id: this.id,
|
|
595
|
+
method: 'getTokenAccounts',
|
|
596
|
+
params,
|
|
597
|
+
}, {
|
|
598
|
+
headers: { 'Content-Type': 'application/json' },
|
|
599
|
+
});
|
|
600
|
+
return response.data.result;
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
throw new Error(`Error in getTokenAccounts: ${error}`);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
sendTransaction(transaction_1) {
|
|
608
|
+
return __awaiter(this, arguments, void 0, function* (transaction, options = {
|
|
609
|
+
skipPreflight: true,
|
|
610
|
+
}) {
|
|
611
|
+
let rawTransaction;
|
|
612
|
+
if (transaction instanceof web3_js_1.VersionedTransaction) {
|
|
613
|
+
rawTransaction = Buffer.from(transaction.serialize()).toString('base64');
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
rawTransaction = transaction.serialize().toString('base64');
|
|
617
|
+
}
|
|
618
|
+
try {
|
|
619
|
+
const url = `${this.connection.rpcEndpoint}`;
|
|
620
|
+
const response = yield axios_1.default.post(url, {
|
|
621
|
+
jsonrpc: '2.0',
|
|
622
|
+
id: this.id,
|
|
623
|
+
method: 'sendTransaction',
|
|
624
|
+
params: [rawTransaction, Object.assign({ encoding: 'base64' }, options)],
|
|
625
|
+
}, {
|
|
626
|
+
headers: { 'Content-Type': 'application/json' },
|
|
627
|
+
});
|
|
628
|
+
if (response.data.error) {
|
|
629
|
+
throw new Error(`RPC error: ${JSON.stringify(response.data.error)}`);
|
|
630
|
+
}
|
|
631
|
+
return response.data.result;
|
|
632
|
+
}
|
|
633
|
+
catch (error) {
|
|
634
|
+
throw new Error(`Error sending transaction: ${error}`);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
exports.RpcClient = RpcClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SFDP_REJECTS_URL = "https://helius-docs.s3.us-east-2.amazonaws.com/sfdp_rejects.json";
|
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./Helius"), exports);
|
|
21
|
+
__exportStar(require("./RpcClient"), exports);
|