@wallfree-dev/solana 0.13.43-beta.0 → 0.13.43-beta.10

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.
@@ -69,6 +69,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
69
69
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
70
  }
71
71
  };
72
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
74
+ if (ar || !(i in from)) {
75
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
76
+ ar[i] = from[i];
77
+ }
78
+ }
79
+ return to.concat(ar || Array.prototype.slice.call(from));
80
+ };
72
81
  Object.defineProperty(exports, "__esModule", { value: true });
73
82
  exports.createSolanaProtocol = exports.SolanaProtocol = exports.SOLANA_UNITS_METADATA = void 0;
74
83
  var module_kit_1 = require("@wallfree-dev/module-kit");
@@ -91,6 +100,75 @@ var SolanaProtocol = /** @class */ (function () {
91
100
  function SolanaProtocol(options) {
92
101
  this.options = options;
93
102
  }
103
+ // Helper for RPC calls with fallback to backup endpoints
104
+ SolanaProtocol.prototype.withFallback = function (fn, maxRetries) {
105
+ var _a, _b, _c, _d, _e;
106
+ if (maxRetries === void 0) { maxRetries = 2; }
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var allUrls, lastError, _i, allUrls_1, rpcUrl, _loop_1, retry, state_1;
109
+ return __generator(this, function (_f) {
110
+ switch (_f.label) {
111
+ case 0:
112
+ allUrls = __spreadArray([this.options.network.rpcUrl], SolanaProtocol.FALLBACK_RPC_URLS, true);
113
+ _i = 0, allUrls_1 = allUrls;
114
+ _f.label = 1;
115
+ case 1:
116
+ if (!(_i < allUrls_1.length)) return [3 /*break*/, 6];
117
+ rpcUrl = allUrls_1[_i];
118
+ _loop_1 = function (retry) {
119
+ var connection, _g, e_1, isTemporaryError;
120
+ return __generator(this, function (_h) {
121
+ switch (_h.label) {
122
+ case 0:
123
+ _h.trys.push([0, 2, , 5]);
124
+ connection = new solanaWeb3.Connection(rpcUrl);
125
+ _g = {};
126
+ return [4 /*yield*/, fn(connection)];
127
+ case 1: return [2 /*return*/, (_g.value = _h.sent(), _g)];
128
+ case 2:
129
+ e_1 = _h.sent();
130
+ lastError = e_1;
131
+ isTemporaryError = ((_a = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) === null || _a === void 0 ? void 0 : _a.includes('500')) ||
132
+ ((_b = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) === null || _b === void 0 ? void 0 : _b.includes('502')) ||
133
+ ((_c = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) === null || _c === void 0 ? void 0 : _c.includes('503')) ||
134
+ ((_d = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) === null || _d === void 0 ? void 0 : _d.includes('code":19')) ||
135
+ ((_e = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) === null || _e === void 0 ? void 0 : _e.includes('Temporary'));
136
+ if (!isTemporaryError) {
137
+ return [2 /*return*/, "break"];
138
+ }
139
+ if (!(retry < maxRetries - 1)) return [3 /*break*/, 4];
140
+ return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000 * (retry + 1)); })];
141
+ case 3:
142
+ _h.sent();
143
+ _h.label = 4;
144
+ case 4: return [3 /*break*/, 5];
145
+ case 5: return [2 /*return*/];
146
+ }
147
+ });
148
+ };
149
+ retry = 0;
150
+ _f.label = 2;
151
+ case 2:
152
+ if (!(retry < maxRetries)) return [3 /*break*/, 5];
153
+ return [5 /*yield**/, _loop_1(retry)];
154
+ case 3:
155
+ state_1 = _f.sent();
156
+ if (typeof state_1 === "object")
157
+ return [2 /*return*/, state_1.value];
158
+ if (state_1 === "break")
159
+ return [3 /*break*/, 5];
160
+ _f.label = 4;
161
+ case 4:
162
+ retry++;
163
+ return [3 /*break*/, 2];
164
+ case 5:
165
+ _i++;
166
+ return [3 /*break*/, 1];
167
+ case 6: throw lastError;
168
+ }
169
+ });
170
+ });
171
+ };
94
172
  SolanaProtocol.prototype.getMetadata = function () {
95
173
  return __awaiter(this, void 0, void 0, function () {
96
174
  return __generator(this, function (_a) {
@@ -161,9 +239,27 @@ var SolanaProtocol = /** @class */ (function () {
161
239
  });
162
240
  });
163
241
  };
242
+ SolanaProtocol.prototype.validateAddress = function (address) {
243
+ return __awaiter(this, void 0, void 0, function () {
244
+ var pubkey;
245
+ return __generator(this, function (_a) {
246
+ try {
247
+ pubkey = new solanaWeb3.PublicKey(address);
248
+ // Additional check: ensure it's on the ed25519 curve (valid public key)
249
+ // Note: Some special addresses like program IDs may not be on curve, so we accept both
250
+ return [2 /*return*/, pubkey.toBytes().length === 32];
251
+ }
252
+ catch (_b) {
253
+ return [2 /*return*/, false];
254
+ }
255
+ return [2 /*return*/];
256
+ });
257
+ });
258
+ };
164
259
  SolanaProtocol.prototype.getBalanceOfAddress = function (address) {
165
260
  return __awaiter(this, void 0, void 0, function () {
166
- var pubKey, connection, balance, e_1;
261
+ var pubKey, balance, e_2;
262
+ var _this = this;
167
263
  return __generator(this, function (_a) {
168
264
  switch (_a.label) {
169
265
  case 0:
@@ -171,18 +267,19 @@ var SolanaProtocol = /** @class */ (function () {
171
267
  _a.label = 1;
172
268
  case 1:
173
269
  _a.trys.push([1, 3, , 4]);
174
- console.info('[solana][balance] rpcUrl=%s address=%s', this.options.network.rpcUrl, address);
175
- connection = new solanaWeb3.Connection(this.options.network.rpcUrl);
176
- return [4 /*yield*/, connection.getBalance(pubKey)];
270
+ return [4 /*yield*/, this.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
271
+ return __generator(this, function (_a) {
272
+ return [2 /*return*/, connection.getBalance(pubKey)];
273
+ });
274
+ }); })];
177
275
  case 2:
178
276
  balance = _a.sent();
179
- console.info('[solana][balance] success lamports=%s via %s', balance, this.options.network.rpcUrl);
180
277
  return [2 /*return*/, {
181
278
  total: (0, module_kit_1.newAmount)(balance, 'Lamports')
182
279
  }];
183
280
  case 3:
184
- e_1 = _a.sent();
185
- console.error('[solana][balance][error] rpcUrl=%s', this.options.network.rpcUrl, e_1);
281
+ e_2 = _a.sent();
282
+ console.error('[solana][balance][error]', e_2);
186
283
  return [2 /*return*/, { total: (0, module_kit_1.newAmount)(0, 'Lamports') }];
187
284
  case 4: return [2 /*return*/];
188
285
  }
@@ -205,7 +302,7 @@ var SolanaProtocol = /** @class */ (function () {
205
302
  SolanaProtocol.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
206
303
  var _a;
207
304
  return __awaiter(this, void 0, void 0, function () {
208
- var tx, fallbackFeePayer, _b, _c, _d, feePayer, firstIx, decoded, amountLamports, fromAddress, toAddress, fee, connection, feeInfo, e_2, e_3, fallbackTx;
305
+ var tx, fallbackFeePayer, _b, _c, _d, feePayer, firstIx, decoded, amountLamports, fromAddress, toAddress, fee, connection, feeInfo, e_3, e_4, fallbackTx;
209
306
  return __generator(this, function (_e) {
210
307
  switch (_e.label) {
211
308
  case 0:
@@ -245,7 +342,7 @@ var SolanaProtocol = /** @class */ (function () {
245
342
  fee = (0, module_kit_1.newAmount)((_a = feeInfo === null || feeInfo === void 0 ? void 0 : feeInfo.value) !== null && _a !== void 0 ? _a : 5000, 'Lamports');
246
343
  return [3 /*break*/, 7];
247
344
  case 6:
248
- e_2 = _e.sent();
345
+ e_3 = _e.sent();
249
346
  // Network unavailable (e.g., offline vault), use default fee
250
347
  console.warn('[solana][getDetailsFromTransaction] Network unavailable, using default fee');
251
348
  return [3 /*break*/, 7];
@@ -260,8 +357,8 @@ var SolanaProtocol = /** @class */ (function () {
260
357
  }
261
358
  ]];
262
359
  case 8:
263
- e_3 = _e.sent();
264
- console.error('[solana][getDetailsFromTransaction] Failed to parse transaction:', e_3);
360
+ e_4 = _e.sent();
361
+ console.error('[solana][getDetailsFromTransaction] Failed to parse transaction:', e_4);
265
362
  fallbackTx = {
266
363
  from: [],
267
364
  to: [],
@@ -417,107 +514,153 @@ var SolanaProtocol = /** @class */ (function () {
417
514
  SolanaProtocol.prototype.getTransactionsForAddress = function (address, limit, cursor) {
418
515
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
419
516
  return __awaiter(this, void 0, void 0, function () {
420
- var connection, signatures, txs, _i, signatures_1, sigInfo, parsed, amount, fee, from, to, instructions, _m, instructions_1, ix, parsedIx, info, accountKeys, preBalances, postBalances, i, pubkeyStr, diff, sentAmount, blockTime, timestamp, e_4;
421
- return __generator(this, function (_o) {
422
- switch (_o.label) {
517
+ var effectiveLimit, queryOptions_1, signatures, txs, _loop_2, this_1, _i, signatures_1, sigInfo, hasNext, lastSignature, newCursor, e_5;
518
+ var _this = this;
519
+ return __generator(this, function (_m) {
520
+ switch (_m.label) {
423
521
  case 0:
424
- connection = new solanaWeb3.Connection(this.options.network.rpcUrl);
425
- return [4 /*yield*/, connection.getSignaturesForAddress(new solanaWeb3.PublicKey(address), { limit: limit || 10 })];
522
+ _m.trys.push([0, 6, , 7]);
523
+ effectiveLimit = limit || SolanaProtocol.DEFAULT_TX_LIMIT;
524
+ queryOptions_1 = {
525
+ limit: effectiveLimit
526
+ };
527
+ // If cursor has lastSignature, use it for pagination
528
+ if (cursor === null || cursor === void 0 ? void 0 : cursor.lastSignature) {
529
+ queryOptions_1.before = cursor.lastSignature;
530
+ }
531
+ return [4 /*yield*/, this.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
532
+ return __generator(this, function (_a) {
533
+ return [2 /*return*/, connection.getSignaturesForAddress(new solanaWeb3.PublicKey(address), queryOptions_1)];
534
+ });
535
+ }); })];
426
536
  case 1:
427
- signatures = _o.sent();
537
+ signatures = _m.sent();
428
538
  txs = [];
539
+ _loop_2 = function (sigInfo) {
540
+ var parsed, amount, fee, from, to, instructions, _o, instructions_1, ix, parsedIx, info, accountKeys, preBalances, postBalances, i, pubkeyStr, diff, sentAmount, blockTime, timestamp, e_6;
541
+ return __generator(this, function (_p) {
542
+ switch (_p.label) {
543
+ case 0:
544
+ if (!sigInfo.signature) {
545
+ return [2 /*return*/, "continue"];
546
+ }
547
+ _p.label = 1;
548
+ case 1:
549
+ _p.trys.push([1, 3, , 4]);
550
+ return [4 /*yield*/, this_1.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
551
+ return __generator(this, function (_a) {
552
+ return [2 /*return*/, connection.getParsedTransaction(sigInfo.signature, {
553
+ commitment: 'confirmed',
554
+ maxSupportedTransactionVersion: 0
555
+ })];
556
+ });
557
+ }); })];
558
+ case 2:
559
+ parsed = _p.sent();
560
+ if (!parsed) {
561
+ return [2 /*return*/, "continue"];
562
+ }
563
+ amount = (0, module_kit_1.newAmount)(0, 'Lamports');
564
+ fee = (0, module_kit_1.newAmount)((_b = (_a = parsed.meta) === null || _a === void 0 ? void 0 : _a.fee) !== null && _b !== void 0 ? _b : 0, 'Lamports');
565
+ from = [];
566
+ to = [];
567
+ instructions = ((_d = (_c = parsed.transaction) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.instructions) || [];
568
+ for (_o = 0, instructions_1 = instructions; _o < instructions_1.length; _o++) {
569
+ ix = instructions_1[_o];
570
+ // Check if it's a parsed instruction (has 'parsed' property)
571
+ if ('parsed' in ix && ix.parsed) {
572
+ parsedIx = ix;
573
+ if (parsedIx.program === 'system' && ((_e = parsedIx.parsed) === null || _e === void 0 ? void 0 : _e.type) === 'transfer') {
574
+ info = parsedIx.parsed.info;
575
+ if (info) {
576
+ amount = (0, module_kit_1.newAmount)(((_f = info.lamports) === null || _f === void 0 ? void 0 : _f.toString()) || '0', 'Lamports');
577
+ from = info.source ? [info.source] : [];
578
+ to = info.destination ? [info.destination] : [];
579
+ break;
580
+ }
581
+ }
582
+ }
583
+ }
584
+ // Fallback: try to extract from preBalances/postBalances if transfer info not found
585
+ if (from.length === 0 && to.length === 0 && parsed.meta) {
586
+ accountKeys = ((_h = (_g = parsed.transaction) === null || _g === void 0 ? void 0 : _g.message) === null || _h === void 0 ? void 0 : _h.accountKeys) || [];
587
+ preBalances = parsed.meta.preBalances || [];
588
+ postBalances = parsed.meta.postBalances || [];
589
+ for (i = 0; i < accountKeys.length; i++) {
590
+ pubkeyStr = typeof accountKeys[i] === 'string'
591
+ ? accountKeys[i]
592
+ : ((_j = accountKeys[i].pubkey) === null || _j === void 0 ? void 0 : _j.toString()) || accountKeys[i].toString();
593
+ diff = (postBalances[i] || 0) - (preBalances[i] || 0);
594
+ if (diff < 0) {
595
+ // This account sent SOL (balance decreased)
596
+ from.push(pubkeyStr);
597
+ if (amount.value === '0') {
598
+ sentAmount = Math.abs(diff) - (((_k = parsed.meta) === null || _k === void 0 ? void 0 : _k.fee) || 0);
599
+ if (sentAmount > 0) {
600
+ amount = (0, module_kit_1.newAmount)(sentAmount.toString(), 'Lamports');
601
+ }
602
+ }
603
+ }
604
+ else if (diff > 0) {
605
+ // This account received SOL (balance increased)
606
+ to.push(pubkeyStr);
607
+ }
608
+ }
609
+ }
610
+ blockTime = (_l = sigInfo.blockTime) !== null && _l !== void 0 ? _l : parsed.blockTime;
611
+ timestamp = blockTime ? blockTime : Math.floor(Date.now() / 1000);
612
+ txs.push({
613
+ hash: sigInfo.signature,
614
+ timestamp: timestamp,
615
+ status: sigInfo.confirmationStatus || 'processed',
616
+ amount: amount,
617
+ fee: fee,
618
+ from: from,
619
+ to: to,
620
+ isInbound: to.includes(address),
621
+ network: this_1.options.network
622
+ });
623
+ return [3 /*break*/, 4];
624
+ case 3:
625
+ e_6 = _p.sent();
626
+ console.warn('[solana][getTransactionsForAddress] Failed to parse transaction:', sigInfo.signature);
627
+ return [3 /*break*/, 4];
628
+ case 4: return [2 /*return*/];
629
+ }
630
+ });
631
+ };
632
+ this_1 = this;
429
633
  _i = 0, signatures_1 = signatures;
430
- _o.label = 2;
634
+ _m.label = 2;
431
635
  case 2:
432
- if (!(_i < signatures_1.length)) return [3 /*break*/, 7];
636
+ if (!(_i < signatures_1.length)) return [3 /*break*/, 5];
433
637
  sigInfo = signatures_1[_i];
434
- if (!sigInfo.signature) {
435
- return [3 /*break*/, 6];
436
- }
437
- _o.label = 3;
638
+ return [5 /*yield**/, _loop_2(sigInfo)];
438
639
  case 3:
439
- _o.trys.push([3, 5, , 6]);
440
- return [4 /*yield*/, connection.getParsedTransaction(sigInfo.signature, {
441
- commitment: 'confirmed',
442
- maxSupportedTransactionVersion: 0
443
- })];
640
+ _m.sent();
641
+ _m.label = 4;
444
642
  case 4:
445
- parsed = _o.sent();
446
- if (!parsed) {
447
- return [3 /*break*/, 6];
448
- }
449
- amount = (0, module_kit_1.newAmount)(0, 'Lamports');
450
- fee = (0, module_kit_1.newAmount)((_b = (_a = parsed.meta) === null || _a === void 0 ? void 0 : _a.fee) !== null && _b !== void 0 ? _b : 0, 'Lamports');
451
- from = [];
452
- to = [];
453
- instructions = ((_d = (_c = parsed.transaction) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.instructions) || [];
454
- for (_m = 0, instructions_1 = instructions; _m < instructions_1.length; _m++) {
455
- ix = instructions_1[_m];
456
- // Check if it's a parsed instruction (has 'parsed' property)
457
- if ('parsed' in ix && ix.parsed) {
458
- parsedIx = ix;
459
- if (parsedIx.program === 'system' && ((_e = parsedIx.parsed) === null || _e === void 0 ? void 0 : _e.type) === 'transfer') {
460
- info = parsedIx.parsed.info;
461
- if (info) {
462
- amount = (0, module_kit_1.newAmount)(((_f = info.lamports) === null || _f === void 0 ? void 0 : _f.toString()) || '0', 'Lamports');
463
- from = info.source ? [info.source] : [];
464
- to = info.destination ? [info.destination] : [];
465
- break;
466
- }
467
- }
468
- }
469
- }
470
- // Fallback: try to extract from preBalances/postBalances if transfer info not found
471
- if (from.length === 0 && to.length === 0 && parsed.meta) {
472
- accountKeys = ((_h = (_g = parsed.transaction) === null || _g === void 0 ? void 0 : _g.message) === null || _h === void 0 ? void 0 : _h.accountKeys) || [];
473
- preBalances = parsed.meta.preBalances || [];
474
- postBalances = parsed.meta.postBalances || [];
475
- for (i = 0; i < accountKeys.length; i++) {
476
- pubkeyStr = typeof accountKeys[i] === 'string'
477
- ? accountKeys[i]
478
- : ((_j = accountKeys[i].pubkey) === null || _j === void 0 ? void 0 : _j.toString()) || accountKeys[i].toString();
479
- diff = (postBalances[i] || 0) - (preBalances[i] || 0);
480
- if (diff < 0) {
481
- // This account sent SOL (balance decreased)
482
- from.push(pubkeyStr);
483
- if (amount.value === '0') {
484
- sentAmount = Math.abs(diff) - (((_k = parsed.meta) === null || _k === void 0 ? void 0 : _k.fee) || 0);
485
- if (sentAmount > 0) {
486
- amount = (0, module_kit_1.newAmount)(sentAmount.toString(), 'Lamports');
487
- }
488
- }
489
- }
490
- else if (diff > 0) {
491
- // This account received SOL (balance increased)
492
- to.push(pubkeyStr);
493
- }
494
- }
495
- }
496
- blockTime = (_l = sigInfo.blockTime) !== null && _l !== void 0 ? _l : parsed.blockTime;
497
- timestamp = blockTime ? blockTime : Math.floor(Date.now() / 1000);
498
- txs.push({
499
- hash: sigInfo.signature,
500
- timestamp: timestamp,
501
- status: sigInfo.confirmationStatus || 'processed',
502
- amount: amount,
503
- fee: fee,
504
- from: from,
505
- to: to,
506
- isInbound: to.includes(address),
507
- network: this.options.network
508
- });
509
- return [3 /*break*/, 6];
510
- case 5:
511
- e_4 = _o.sent();
512
- console.error('[solana][getTransactionsForAddress] Failed to parse transaction:', sigInfo.signature, e_4);
513
- return [3 /*break*/, 6];
514
- case 6:
515
643
  _i++;
516
644
  return [3 /*break*/, 2];
517
- case 7: return [2 /*return*/, {
518
- transactions: txs,
519
- cursor: { hasNext: false }
520
- }];
645
+ case 5:
646
+ hasNext = signatures.length === effectiveLimit;
647
+ lastSignature = signatures.length > 0 ? signatures[signatures.length - 1].signature : undefined;
648
+ newCursor = {
649
+ hasNext: hasNext,
650
+ lastSignature: lastSignature
651
+ };
652
+ return [2 /*return*/, {
653
+ transactions: txs,
654
+ cursor: newCursor
655
+ }];
656
+ case 6:
657
+ e_5 = _m.sent();
658
+ console.error('[solana][getTransactionsForAddress] Failed:', e_5);
659
+ return [2 /*return*/, {
660
+ transactions: [],
661
+ cursor: { hasNext: false }
662
+ }];
663
+ case 7: return [2 /*return*/];
521
664
  }
522
665
  });
523
666
  });
@@ -538,14 +681,20 @@ var SolanaProtocol = /** @class */ (function () {
538
681
  SolanaProtocol.prototype.getTransactionStatus = function (transactionIds) {
539
682
  var _a;
540
683
  return __awaiter(this, void 0, void 0, function () {
541
- var connection, statuses, result, i, id, status_1, confirmationStatus;
684
+ var statuses, result, i, id, status_1, confirmationStatus;
685
+ var _this = this;
542
686
  return __generator(this, function (_b) {
543
687
  switch (_b.label) {
544
- case 0:
545
- connection = new solanaWeb3.Connection(this.options.network.rpcUrl);
546
- return [4 /*yield*/, connection.getSignatureStatuses(transactionIds)];
688
+ case 0: return [4 /*yield*/, this.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
689
+ return __generator(this, function (_a) {
690
+ switch (_a.label) {
691
+ case 0: return [4 /*yield*/, connection.getSignatureStatuses(transactionIds)];
692
+ case 1: return [2 /*return*/, (_a.sent()).value];
693
+ }
694
+ });
695
+ }); })];
547
696
  case 1:
548
- statuses = (_b.sent()).value;
697
+ statuses = _b.sent();
549
698
  result = {};
550
699
  for (i = 0; i < transactionIds.length; i++) {
551
700
  id = transactionIds[i];
@@ -578,16 +727,14 @@ var SolanaProtocol = /** @class */ (function () {
578
727
  });
579
728
  };
580
729
  SolanaProtocol.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, configuration) {
581
- var _a;
582
730
  return __awaiter(this, void 0, void 0, function () {
583
- var connection, fromAddress, fromPubkey, transaction, _i, details_1, detail, latestBlockhash, feeForMessage, lamportsFee;
584
- return __generator(this, function (_b) {
585
- switch (_b.label) {
586
- case 0:
587
- connection = new solanaWeb3.Connection(this.options.network.rpcUrl);
588
- return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
731
+ var fromAddress, fromPubkey, transaction, _i, details_1, detail, lamportsFee;
732
+ var _this = this;
733
+ return __generator(this, function (_a) {
734
+ switch (_a.label) {
735
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
589
736
  case 1:
590
- fromAddress = _b.sent();
737
+ fromAddress = _a.sent();
591
738
  fromPubkey = new solanaWeb3.PublicKey(fromAddress);
592
739
  transaction = new solanaWeb3.Transaction();
593
740
  for (_i = 0, details_1 = details; _i < details_1.length; _i++) {
@@ -599,14 +746,24 @@ var SolanaProtocol = /** @class */ (function () {
599
746
  }));
600
747
  }
601
748
  transaction.feePayer = fromPubkey;
602
- return [4 /*yield*/, connection.getLatestBlockhash()];
749
+ return [4 /*yield*/, this.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
750
+ var latestBlockhash, feeForMessage;
751
+ var _a;
752
+ return __generator(this, function (_b) {
753
+ switch (_b.label) {
754
+ case 0: return [4 /*yield*/, connection.getLatestBlockhash()];
755
+ case 1:
756
+ latestBlockhash = _b.sent();
757
+ transaction.recentBlockhash = latestBlockhash.blockhash;
758
+ return [4 /*yield*/, connection.getFeeForMessage(transaction.compileMessage())];
759
+ case 2:
760
+ feeForMessage = _b.sent();
761
+ return [2 /*return*/, (_a = feeForMessage === null || feeForMessage === void 0 ? void 0 : feeForMessage.value) !== null && _a !== void 0 ? _a : 5000];
762
+ }
763
+ });
764
+ }); }).catch(function () { return 5000; })];
603
765
  case 2:
604
- latestBlockhash = _b.sent();
605
- transaction.recentBlockhash = latestBlockhash.blockhash;
606
- return [4 /*yield*/, connection.getFeeForMessage(transaction.compileMessage())];
607
- case 3:
608
- feeForMessage = _b.sent();
609
- lamportsFee = (_a = feeForMessage === null || feeForMessage === void 0 ? void 0 : feeForMessage.value) !== null && _a !== void 0 ? _a : 5000;
766
+ lamportsFee = _a.sent();
610
767
  return [2 /*return*/, {
611
768
  low: (0, module_kit_1.newAmount)(lamportsFee, 'Lamports'),
612
769
  medium: (0, module_kit_1.newAmount)(lamportsFee, 'Lamports'),
@@ -618,12 +775,11 @@ var SolanaProtocol = /** @class */ (function () {
618
775
  };
619
776
  SolanaProtocol.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
620
777
  return __awaiter(this, void 0, void 0, function () {
621
- var connection, fromAddress, fromPubkey, transaction, _i, details_2, detail, blockhash, serialized;
778
+ var fromAddress, fromPubkey, transaction, _i, details_2, detail, blockhash, serialized;
779
+ var _this = this;
622
780
  return __generator(this, function (_a) {
623
781
  switch (_a.label) {
624
- case 0:
625
- connection = new solanaWeb3.Connection(this.options.network.rpcUrl);
626
- return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
782
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
627
783
  case 1:
628
784
  fromAddress = _a.sent();
629
785
  fromPubkey = new solanaWeb3.PublicKey(fromAddress);
@@ -637,9 +793,19 @@ var SolanaProtocol = /** @class */ (function () {
637
793
  }));
638
794
  }
639
795
  transaction.feePayer = fromPubkey;
640
- return [4 /*yield*/, connection.getLatestBlockhash()];
796
+ return [4 /*yield*/, this.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
797
+ var result;
798
+ return __generator(this, function (_a) {
799
+ switch (_a.label) {
800
+ case 0: return [4 /*yield*/, connection.getLatestBlockhash()];
801
+ case 1:
802
+ result = _a.sent();
803
+ return [2 /*return*/, result.blockhash];
804
+ }
805
+ });
806
+ }); })];
641
807
  case 2:
642
- blockhash = (_a.sent()).blockhash;
808
+ blockhash = _a.sent();
643
809
  transaction.recentBlockhash = blockhash;
644
810
  serialized = transaction.serialize({ requireAllSignatures: false }).toString('hex');
645
811
  return [2 /*return*/, {
@@ -652,13 +818,17 @@ var SolanaProtocol = /** @class */ (function () {
652
818
  };
653
819
  SolanaProtocol.prototype.broadcastTransaction = function (transaction) {
654
820
  return __awaiter(this, void 0, void 0, function () {
655
- var connection, txBuffer, signature;
821
+ var txBuffer, signature;
822
+ var _this = this;
656
823
  return __generator(this, function (_a) {
657
824
  switch (_a.label) {
658
825
  case 0:
659
- connection = new solanaWeb3.Connection(this.options.network.rpcUrl);
660
826
  txBuffer = Buffer.from(transaction.serialized, 'hex');
661
- return [4 /*yield*/, connection.sendRawTransaction(txBuffer)];
827
+ return [4 /*yield*/, this.withFallback(function (connection) { return __awaiter(_this, void 0, void 0, function () {
828
+ return __generator(this, function (_a) {
829
+ return [2 /*return*/, connection.sendRawTransaction(txBuffer)];
830
+ });
831
+ }); })];
662
832
  case 1:
663
833
  signature = _a.sent();
664
834
  return [2 /*return*/, signature];
@@ -673,6 +843,12 @@ var SolanaProtocol = /** @class */ (function () {
673
843
  });
674
844
  });
675
845
  };
846
+ // Fallback RPC endpoints for reliability
847
+ SolanaProtocol.FALLBACK_RPC_URLS = [
848
+ 'https://solana.drpc.org'
849
+ ];
850
+ // Default number of transactions to fetch per page
851
+ SolanaProtocol.DEFAULT_TX_LIMIT = 10;
676
852
  return SolanaProtocol;
677
853
  }());
678
854
  exports.SolanaProtocol = SolanaProtocol;
@@ -681,7 +857,7 @@ function createSolanaProtocol(options) {
681
857
  var defaultNetwork = {
682
858
  name: 'Solana Mainnet',
683
859
  type: 'mainnet',
684
- rpcUrl: 'https://solana.drpc.org',
860
+ rpcUrl: 'https://solana-rpc.publicnode.com',
685
861
  blockExplorerUrl: 'https://explorer.solana.com',
686
862
  chainId: 101,
687
863
  blockExplorerApi: ''