@alleyboss/micropay-solana-x402-paywall 2.3.1 → 3.0.1

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.
Files changed (72) hide show
  1. package/README.md +85 -139
  2. package/dist/agent/index.cjs +1 -2
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +11 -2
  5. package/dist/agent/index.d.ts +11 -2
  6. package/dist/agent/index.js +1 -2
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/client/index.cjs +1 -1
  9. package/dist/client/index.cjs.map +1 -1
  10. package/dist/client/index.d.cts +10 -1
  11. package/dist/client/index.d.ts +10 -1
  12. package/dist/client/index.js +1 -1
  13. package/dist/client/index.js.map +1 -1
  14. package/dist/express/index.cjs +79 -0
  15. package/dist/express/index.cjs.map +1 -0
  16. package/dist/express/index.d.cts +40 -0
  17. package/dist/express/index.d.ts +40 -0
  18. package/dist/express/index.js +76 -0
  19. package/dist/express/index.js.map +1 -0
  20. package/dist/index.cjs +257 -1357
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +6 -12
  23. package/dist/index.d.ts +6 -12
  24. package/dist/index.js +239 -1319
  25. package/dist/index.js.map +1 -1
  26. package/dist/session/index.cjs.map +1 -1
  27. package/dist/session/index.d.cts +1 -1
  28. package/dist/session/index.d.ts +1 -1
  29. package/dist/session/index.js.map +1 -1
  30. package/dist/{session-D2IoWAWV.d.cts → types-BWYQMw03.d.cts} +1 -16
  31. package/dist/{session-D2IoWAWV.d.ts → types-BWYQMw03.d.ts} +1 -16
  32. package/package.json +28 -68
  33. package/dist/client-D-dteoJw.d.cts +0 -63
  34. package/dist/client-DfCIRrNG.d.ts +0 -63
  35. package/dist/memory-Daxkczti.d.cts +0 -29
  36. package/dist/memory-Daxkczti.d.ts +0 -29
  37. package/dist/middleware/index.cjs +0 -273
  38. package/dist/middleware/index.cjs.map +0 -1
  39. package/dist/middleware/index.d.cts +0 -91
  40. package/dist/middleware/index.d.ts +0 -91
  41. package/dist/middleware/index.js +0 -267
  42. package/dist/middleware/index.js.map +0 -1
  43. package/dist/nextjs-BDyOqGAq.d.cts +0 -81
  44. package/dist/nextjs-CbX8_9yK.d.ts +0 -81
  45. package/dist/payment-BGp7eMQl.d.cts +0 -103
  46. package/dist/payment-BGp7eMQl.d.ts +0 -103
  47. package/dist/priority-fees-C-OH4Trr.d.cts +0 -50
  48. package/dist/priority-fees-C-OH4Trr.d.ts +0 -50
  49. package/dist/solana/index.cjs +0 -589
  50. package/dist/solana/index.cjs.map +0 -1
  51. package/dist/solana/index.d.cts +0 -195
  52. package/dist/solana/index.d.ts +0 -195
  53. package/dist/solana/index.js +0 -567
  54. package/dist/solana/index.js.map +0 -1
  55. package/dist/store/index.cjs +0 -99
  56. package/dist/store/index.cjs.map +0 -1
  57. package/dist/store/index.d.cts +0 -38
  58. package/dist/store/index.d.ts +0 -38
  59. package/dist/store/index.js +0 -96
  60. package/dist/store/index.js.map +0 -1
  61. package/dist/utils/index.cjs +0 -68
  62. package/dist/utils/index.cjs.map +0 -1
  63. package/dist/utils/index.d.cts +0 -30
  64. package/dist/utils/index.d.ts +0 -30
  65. package/dist/utils/index.js +0 -65
  66. package/dist/utils/index.js.map +0 -1
  67. package/dist/x402/index.cjs +0 -387
  68. package/dist/x402/index.cjs.map +0 -1
  69. package/dist/x402/index.d.cts +0 -96
  70. package/dist/x402/index.d.ts +0 -96
  71. package/dist/x402/index.js +0 -375
  72. package/dist/x402/index.js.map +0 -1
@@ -1,567 +0,0 @@
1
- import { PublicKey, LAMPORTS_PER_SOL, ComputeBudgetProgram, TransactionMessage, VersionedTransaction, clusterApiUrl, Connection } from '@solana/web3.js';
2
-
3
- // src/solana/client.ts
4
- var cachedConnection = null;
5
- var cachedNetwork = null;
6
- var cachedFallbacks = [];
7
- var cachedFallbackEnabled = false;
8
- function buildRpcUrl(config) {
9
- const { network, rpcUrl, tatumApiKey } = config;
10
- if (rpcUrl) {
11
- if (rpcUrl.includes("tatum.io") && tatumApiKey && !rpcUrl.includes(tatumApiKey)) {
12
- return rpcUrl.endsWith("/") ? `${rpcUrl}${tatumApiKey}` : `${rpcUrl}/${tatumApiKey}`;
13
- }
14
- return rpcUrl;
15
- }
16
- if (tatumApiKey) {
17
- const baseUrl = network === "mainnet-beta" ? "https://solana-mainnet.gateway.tatum.io" : "https://solana-devnet.gateway.tatum.io";
18
- return `${baseUrl}/${tatumApiKey}`;
19
- }
20
- return clusterApiUrl(network);
21
- }
22
- function createConnection(rpcUrl) {
23
- return new Connection(rpcUrl, {
24
- commitment: "confirmed",
25
- confirmTransactionInitialTimeout: 6e4
26
- });
27
- }
28
- function getConnection(config) {
29
- const { network } = config;
30
- if (cachedConnection && cachedNetwork === network) {
31
- return cachedConnection;
32
- }
33
- const rpcUrl = buildRpcUrl(config);
34
- cachedConnection = createConnection(rpcUrl);
35
- cachedNetwork = network;
36
- cachedFallbackEnabled = config.enableFallback ?? false;
37
- cachedFallbacks = [];
38
- if (cachedFallbackEnabled && config.fallbackRpcUrls?.length) {
39
- cachedFallbacks = config.fallbackRpcUrls.map(createConnection);
40
- }
41
- return cachedConnection;
42
- }
43
- function getConnectionWithFallback(config) {
44
- const connection = getConnection(config);
45
- return {
46
- connection,
47
- fallbacks: cachedFallbacks,
48
- fallbackEnabled: cachedFallbackEnabled
49
- };
50
- }
51
- async function withFallback(config, operation) {
52
- const { connection, fallbacks, fallbackEnabled } = getConnectionWithFallback(config);
53
- try {
54
- return await operation(connection);
55
- } catch (error) {
56
- if (!fallbackEnabled || fallbacks.length === 0) {
57
- throw error;
58
- }
59
- if (!isRetryableError(error)) {
60
- throw error;
61
- }
62
- for (let i = 0; i < fallbacks.length; i++) {
63
- try {
64
- return await operation(fallbacks[i]);
65
- } catch (fallbackError) {
66
- if (i === fallbacks.length - 1) {
67
- throw fallbackError;
68
- }
69
- }
70
- }
71
- throw error;
72
- }
73
- }
74
- function isRetryableError(error) {
75
- if (error instanceof Error) {
76
- const message = error.message.toLowerCase();
77
- return message.includes("429") || message.includes("503") || message.includes("502") || message.includes("timeout") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("rate limit");
78
- }
79
- return false;
80
- }
81
- function resetConnection() {
82
- cachedConnection = null;
83
- cachedNetwork = null;
84
- }
85
- function isMainnet(network) {
86
- return network === "mainnet-beta";
87
- }
88
- function toX402Network(network) {
89
- return network === "mainnet-beta" ? "solana-mainnet" : "solana-devnet";
90
- }
91
- var SIGNATURE_REGEX = /^[1-9A-HJ-NP-Za-km-z]{87,88}$/;
92
- var WALLET_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
93
- function isValidSignature(signature) {
94
- if (!signature || typeof signature !== "string") return false;
95
- return SIGNATURE_REGEX.test(signature);
96
- }
97
- function isValidWalletAddress(address) {
98
- if (!address || typeof address !== "string") return false;
99
- return WALLET_REGEX.test(address);
100
- }
101
- function parseSOLTransfer(transaction, expectedRecipient) {
102
- const instructions = transaction.transaction.message.instructions;
103
- for (const ix of instructions) {
104
- if ("parsed" in ix && ix.program === "system") {
105
- const parsed = ix.parsed;
106
- if (parsed.type === "transfer" && parsed.info.destination === expectedRecipient) {
107
- return {
108
- from: parsed.info.source,
109
- to: parsed.info.destination,
110
- amount: BigInt(parsed.info.lamports)
111
- };
112
- }
113
- }
114
- }
115
- if (transaction.meta?.innerInstructions) {
116
- for (const inner of transaction.meta.innerInstructions) {
117
- for (const ix of inner.instructions) {
118
- if ("parsed" in ix && ix.program === "system") {
119
- const parsed = ix.parsed;
120
- if (parsed.type === "transfer" && parsed.info.destination === expectedRecipient) {
121
- return {
122
- from: parsed.info.source,
123
- to: parsed.info.destination,
124
- amount: BigInt(parsed.info.lamports)
125
- };
126
- }
127
- }
128
- }
129
- }
130
- }
131
- return null;
132
- }
133
- async function verifyPayment(params) {
134
- const {
135
- signature,
136
- expectedRecipient,
137
- expectedAmount,
138
- maxAgeSeconds = 300,
139
- clientConfig,
140
- signatureStore
141
- } = params;
142
- if (!isValidSignature(signature)) {
143
- return { valid: false, confirmed: false, signature, error: "Invalid signature format" };
144
- }
145
- if (!isValidWalletAddress(expectedRecipient)) {
146
- return { valid: false, confirmed: false, signature, error: "Invalid recipient address" };
147
- }
148
- if (expectedAmount <= 0n) {
149
- return { valid: false, confirmed: false, signature, error: "Invalid expected amount" };
150
- }
151
- if (signatureStore) {
152
- const isUsed = await signatureStore.hasBeenUsed(signature);
153
- if (isUsed) {
154
- return { valid: false, confirmed: true, signature, error: "Signature already used" };
155
- }
156
- }
157
- const effectiveMaxAge = Math.min(Math.max(maxAgeSeconds, 60), 3600);
158
- const connection = getConnection(clientConfig);
159
- try {
160
- const transaction = await connection.getParsedTransaction(signature, {
161
- commitment: "confirmed",
162
- maxSupportedTransactionVersion: 0
163
- });
164
- if (!transaction) {
165
- return { valid: false, confirmed: false, signature, error: "Transaction not found" };
166
- }
167
- if (transaction.meta?.err) {
168
- return {
169
- valid: false,
170
- confirmed: true,
171
- signature,
172
- error: "Transaction failed on-chain"
173
- };
174
- }
175
- if (transaction.blockTime) {
176
- const now = Math.floor(Date.now() / 1e3);
177
- if (now - transaction.blockTime > effectiveMaxAge) {
178
- return { valid: false, confirmed: true, signature, error: "Transaction too old" };
179
- }
180
- if (transaction.blockTime > now + 60) {
181
- return { valid: false, confirmed: true, signature, error: "Invalid transaction time" };
182
- }
183
- }
184
- const transferDetails = parseSOLTransfer(transaction, expectedRecipient);
185
- if (!transferDetails) {
186
- return {
187
- valid: false,
188
- confirmed: true,
189
- signature,
190
- error: "No valid SOL transfer to recipient found"
191
- };
192
- }
193
- if (transferDetails.amount < expectedAmount) {
194
- return {
195
- valid: false,
196
- confirmed: true,
197
- signature,
198
- from: transferDetails.from,
199
- to: transferDetails.to,
200
- amount: transferDetails.amount,
201
- error: "Insufficient payment amount"
202
- };
203
- }
204
- return {
205
- valid: true,
206
- confirmed: true,
207
- signature,
208
- from: transferDetails.from,
209
- to: transferDetails.to,
210
- amount: transferDetails.amount,
211
- blockTime: transaction.blockTime ?? void 0,
212
- slot: transaction.slot
213
- };
214
- } catch (error) {
215
- return {
216
- valid: false,
217
- confirmed: false,
218
- signature,
219
- error: "Verification failed"
220
- };
221
- }
222
- }
223
- async function waitForConfirmation(signature, clientConfig) {
224
- if (!isValidSignature(signature)) {
225
- return { confirmed: false, error: "Invalid signature format" };
226
- }
227
- const connection = getConnection(clientConfig);
228
- try {
229
- const confirmation = await connection.confirmTransaction(signature, "confirmed");
230
- if (confirmation.value.err) {
231
- return { confirmed: false, error: "Transaction failed" };
232
- }
233
- return { confirmed: true, slot: confirmation.context?.slot };
234
- } catch {
235
- return { confirmed: false, error: "Confirmation timeout" };
236
- }
237
- }
238
- async function getWalletTransactions(walletAddress, clientConfig, limit = 20) {
239
- if (!isValidWalletAddress(walletAddress)) {
240
- return [];
241
- }
242
- const safeLimit = Math.min(Math.max(limit, 1), 100);
243
- const connection = getConnection(clientConfig);
244
- try {
245
- const pubkey = new PublicKey(walletAddress);
246
- const signatures = await connection.getSignaturesForAddress(pubkey, { limit: safeLimit });
247
- return signatures.map((sig) => ({
248
- signature: sig.signature,
249
- blockTime: sig.blockTime ?? void 0,
250
- slot: sig.slot
251
- }));
252
- } catch {
253
- return [];
254
- }
255
- }
256
- function lamportsToSol(lamports) {
257
- return Number(lamports) / LAMPORTS_PER_SOL;
258
- }
259
- function solToLamports(sol) {
260
- if (!Number.isFinite(sol) || sol < 0) {
261
- throw new Error("Invalid SOL amount");
262
- }
263
- return BigInt(Math.floor(sol * LAMPORTS_PER_SOL));
264
- }
265
-
266
- // src/types/payment.ts
267
- var TOKEN_MINTS = {
268
- /** USDC on mainnet */
269
- USDC_MAINNET: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
270
- /** USDC on devnet */
271
- USDC_DEVNET: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",
272
- /** USDT on mainnet */
273
- USDT_MAINNET: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
274
- };
275
-
276
- // src/solana/spl.ts
277
- var SIGNATURE_REGEX2 = /^[1-9A-HJ-NP-Za-km-z]{87,88}$/;
278
- var WALLET_REGEX2 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
279
- function resolveMintAddress(asset, network) {
280
- if (asset === "native") return null;
281
- if (asset === "usdc") {
282
- return network === "mainnet-beta" ? TOKEN_MINTS.USDC_MAINNET : TOKEN_MINTS.USDC_DEVNET;
283
- }
284
- if (asset === "usdt") {
285
- return TOKEN_MINTS.USDT_MAINNET;
286
- }
287
- if (typeof asset === "object" && "mint" in asset) {
288
- return asset.mint;
289
- }
290
- return null;
291
- }
292
- function getTokenDecimals(asset) {
293
- if (asset === "native") return 9;
294
- if (asset === "usdc" || asset === "usdt") return 6;
295
- if (typeof asset === "object" && "decimals" in asset) {
296
- return asset.decimals ?? 6;
297
- }
298
- return 6;
299
- }
300
- function parseSPLTransfer(transaction, expectedRecipient, expectedMint) {
301
- const instructions = transaction.transaction.message.instructions;
302
- for (const ix of instructions) {
303
- if ("parsed" in ix && (ix.program === "spl-token" || ix.program === "spl-token-2022")) {
304
- const parsed = ix.parsed;
305
- if (parsed.type === "transfer" || parsed.type === "transferChecked") {
306
- const amount = parsed.info.amount || parsed.info.tokenAmount?.amount;
307
- if (amount && parsed.info.destination) {
308
- return {
309
- from: parsed.info.authority || parsed.info.source || "",
310
- to: parsed.info.destination,
311
- amount: BigInt(amount),
312
- mint: parsed.info.mint || expectedMint
313
- };
314
- }
315
- }
316
- }
317
- }
318
- if (transaction.meta?.innerInstructions) {
319
- for (const inner of transaction.meta.innerInstructions) {
320
- for (const ix of inner.instructions) {
321
- if ("parsed" in ix && (ix.program === "spl-token" || ix.program === "spl-token-2022")) {
322
- const parsed = ix.parsed;
323
- if (parsed.type === "transfer" || parsed.type === "transferChecked") {
324
- const amount = parsed.info.amount || parsed.info.tokenAmount?.amount;
325
- if (amount) {
326
- return {
327
- from: parsed.info.authority || parsed.info.source || "",
328
- to: parsed.info.destination || "",
329
- amount: BigInt(amount),
330
- mint: parsed.info.mint || expectedMint
331
- };
332
- }
333
- }
334
- }
335
- }
336
- }
337
- }
338
- if (transaction.meta?.postTokenBalances && transaction.meta?.preTokenBalances) {
339
- const preBalances = transaction.meta.preTokenBalances;
340
- const postBalances = transaction.meta.postTokenBalances;
341
- for (const post of postBalances) {
342
- if (post.mint === expectedMint && post.owner === expectedRecipient) {
343
- const pre = preBalances.find(
344
- (p) => p.accountIndex === post.accountIndex
345
- );
346
- const preAmount = BigInt(pre?.uiTokenAmount?.amount || "0");
347
- const postAmount = BigInt(post.uiTokenAmount?.amount || "0");
348
- const transferred = postAmount - preAmount;
349
- if (transferred > 0n) {
350
- return {
351
- from: "",
352
- // Can't determine from balance changes
353
- to: expectedRecipient,
354
- amount: transferred,
355
- mint: expectedMint
356
- };
357
- }
358
- }
359
- }
360
- }
361
- return null;
362
- }
363
- async function verifySPLPayment(params) {
364
- const {
365
- signature,
366
- expectedRecipient,
367
- expectedAmount,
368
- asset,
369
- clientConfig,
370
- maxAgeSeconds = 300,
371
- signatureStore
372
- } = params;
373
- if (signatureStore) {
374
- const isUsed = await signatureStore.hasBeenUsed(signature);
375
- if (isUsed) {
376
- return { valid: false, confirmed: true, signature, error: "Signature already used" };
377
- }
378
- }
379
- if (!SIGNATURE_REGEX2.test(signature)) {
380
- return { valid: false, confirmed: false, signature, error: "Invalid signature format" };
381
- }
382
- if (!WALLET_REGEX2.test(expectedRecipient)) {
383
- return { valid: false, confirmed: false, signature, error: "Invalid recipient address" };
384
- }
385
- const mintAddress = resolveMintAddress(asset, clientConfig.network);
386
- if (!mintAddress) {
387
- return { valid: false, confirmed: false, signature, error: "Invalid asset configuration" };
388
- }
389
- if (expectedAmount <= 0n) {
390
- return { valid: false, confirmed: false, signature, error: "Invalid expected amount" };
391
- }
392
- const effectiveMaxAge = Math.min(Math.max(maxAgeSeconds, 60), 3600);
393
- const connection = getConnection(clientConfig);
394
- try {
395
- const transaction = await connection.getParsedTransaction(signature, {
396
- commitment: "confirmed",
397
- maxSupportedTransactionVersion: 0
398
- });
399
- if (!transaction) {
400
- return { valid: false, confirmed: false, signature, error: "Transaction not found" };
401
- }
402
- if (transaction.meta?.err) {
403
- return { valid: false, confirmed: true, signature, error: "Transaction failed on-chain" };
404
- }
405
- if (transaction.blockTime) {
406
- const now = Math.floor(Date.now() / 1e3);
407
- if (now - transaction.blockTime > effectiveMaxAge) {
408
- return { valid: false, confirmed: true, signature, error: "Transaction too old" };
409
- }
410
- if (transaction.blockTime > now + 60) {
411
- return { valid: false, confirmed: true, signature, error: "Invalid transaction time" };
412
- }
413
- }
414
- const transfer = parseSPLTransfer(transaction, expectedRecipient, mintAddress);
415
- if (!transfer) {
416
- return {
417
- valid: false,
418
- confirmed: true,
419
- signature,
420
- error: "No valid token transfer to recipient found"
421
- };
422
- }
423
- if (transfer.to) {
424
- try {
425
- const destinationInfo = await connection.getParsedAccountInfo(new PublicKey(transfer.to));
426
- const owner = destinationInfo.value?.data?.parsed?.info?.owner;
427
- if (owner && owner !== expectedRecipient) {
428
- return {
429
- valid: false,
430
- confirmed: true,
431
- signature,
432
- error: "Recipient mismatch: Token account not owned by merchant"
433
- };
434
- }
435
- } catch (e) {
436
- return {
437
- valid: false,
438
- confirmed: true,
439
- signature,
440
- error: "Could not verify token account owner"
441
- };
442
- }
443
- }
444
- if (transfer.mint !== mintAddress) {
445
- return {
446
- valid: false,
447
- confirmed: true,
448
- signature,
449
- error: "Token mint mismatch"
450
- };
451
- }
452
- if (transfer.amount < expectedAmount) {
453
- return {
454
- valid: false,
455
- confirmed: true,
456
- signature,
457
- from: transfer.from,
458
- to: transfer.to,
459
- mint: transfer.mint,
460
- amount: transfer.amount,
461
- error: "Insufficient payment amount"
462
- };
463
- }
464
- return {
465
- valid: true,
466
- confirmed: true,
467
- signature,
468
- from: transfer.from,
469
- to: transfer.to,
470
- mint: transfer.mint,
471
- amount: transfer.amount,
472
- blockTime: transaction.blockTime ?? void 0,
473
- slot: transaction.slot
474
- };
475
- } catch {
476
- return { valid: false, confirmed: false, signature, error: "Verification failed" };
477
- }
478
- }
479
- function isNativeAsset(asset) {
480
- return asset === "native";
481
- }
482
- var DEFAULT_COMPUTE_UNITS = 2e5;
483
- var DEFAULT_MICRO_LAMPORTS = 1e3;
484
- function createPriorityFeeInstructions(config = {}) {
485
- const { enabled = false, microLamports, computeUnits } = config;
486
- if (!enabled) {
487
- return [];
488
- }
489
- const instructions = [];
490
- const units = computeUnits ?? DEFAULT_COMPUTE_UNITS;
491
- instructions.push(ComputeBudgetProgram.setComputeUnitLimit({ units }));
492
- const price = microLamports ?? DEFAULT_MICRO_LAMPORTS;
493
- instructions.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: price }));
494
- return instructions;
495
- }
496
- async function estimatePriorityFee(connection, accounts = []) {
497
- try {
498
- const fees = await connection.getRecentPrioritizationFees({
499
- lockedWritableAccounts: accounts
500
- });
501
- if (fees.length === 0) {
502
- return DEFAULT_MICRO_LAMPORTS;
503
- }
504
- const sortedFees = fees.map((f) => f.prioritizationFee).filter((f) => f > 0).sort((a, b) => a - b);
505
- if (sortedFees.length === 0) {
506
- return DEFAULT_MICRO_LAMPORTS;
507
- }
508
- const medianIndex = Math.floor(sortedFees.length / 2);
509
- return sortedFees[medianIndex];
510
- } catch {
511
- return DEFAULT_MICRO_LAMPORTS;
512
- }
513
- }
514
- function calculatePriorityFeeCost(microLamportsPerCU, computeUnits) {
515
- return Math.ceil(microLamportsPerCU * computeUnits / 1e6);
516
- }
517
- async function buildVersionedTransaction(config) {
518
- const {
519
- connection,
520
- payer,
521
- instructions,
522
- lookupTables = [],
523
- priorityFee,
524
- recentBlockhash
525
- } = config;
526
- const priorityIxs = createPriorityFeeInstructions(priorityFee);
527
- const allInstructions = [...priorityIxs, ...instructions];
528
- let blockhash;
529
- let lastValidBlockHeight;
530
- if (recentBlockhash) {
531
- blockhash = recentBlockhash;
532
- const slot = await connection.getSlot();
533
- lastValidBlockHeight = slot + 150;
534
- } else {
535
- const latestBlockhash = await connection.getLatestBlockhash("confirmed");
536
- blockhash = latestBlockhash.blockhash;
537
- lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
538
- }
539
- const message = new TransactionMessage({
540
- payerKey: payer,
541
- recentBlockhash: blockhash,
542
- instructions: allInstructions
543
- }).compileToV0Message(lookupTables);
544
- const transaction = new VersionedTransaction(message);
545
- return {
546
- transaction,
547
- blockhash,
548
- lastValidBlockHeight
549
- };
550
- }
551
- async function fetchLookupTables(connection, addresses) {
552
- const tables = [];
553
- for (const address of addresses) {
554
- const result = await connection.getAddressLookupTable(address);
555
- if (result.value) {
556
- tables.push(result.value);
557
- }
558
- }
559
- return tables;
560
- }
561
- function isVersionedTransaction(tx) {
562
- return tx instanceof VersionedTransaction;
563
- }
564
-
565
- export { buildVersionedTransaction, calculatePriorityFeeCost, createPriorityFeeInstructions, estimatePriorityFee, fetchLookupTables, getConnection, getConnectionWithFallback, getTokenDecimals, getWalletTransactions, isMainnet, isNativeAsset, isVersionedTransaction, lamportsToSol, resetConnection, resolveMintAddress, solToLamports, toX402Network, verifyPayment, verifySPLPayment, waitForConfirmation, withFallback };
566
- //# sourceMappingURL=index.js.map
567
- //# sourceMappingURL=index.js.map