@@ -403,12 +403,12 @@ export async function getWritableAccounts(
403
403
return msg . compiledInstructions
404
404
. flatMap ( ( ix ) => ix . accountKeyIndexes )
405
405
. map ( ( k ) => ( msg . isAccountWritable ( k ) ? keys . get ( k ) : null ) )
406
- . filter ( ( k ) => ! ! k ) as PublicKey [ ] ;
406
+ . filter ( Boolean ) as PublicKey [ ] ;
407
407
} else {
408
408
return transaction . instructions
409
409
. flatMap ( ( ix ) => ix . keys )
410
410
. map ( ( k ) => ( k . isWritable ? k . pubkey : null ) )
411
- . filter ( ( k ) => ! ! k ) as PublicKey [ ] ;
411
+ . filter ( Boolean ) as PublicKey [ ] ;
412
412
}
413
413
}
414
414
@@ -481,6 +481,7 @@ interface RpcResponse {
481
481
482
482
// Helper function to calculate the priority fee using the Triton One API
483
483
// See https://docs.triton.one/chains/solana/improved-priority-fees-api
484
+ // NOTE: this is currently an experimental feature
484
485
export async function determinePriorityFeeTritonOne (
485
486
connection : Connection ,
486
487
transaction : Transaction | VersionedTransaction ,
@@ -504,42 +505,39 @@ export async function determinePriorityFeeTritonOne(
504
505
} ,
505
506
] ;
506
507
507
- try {
508
- const response = ( await rpcRequest (
509
- 'getRecentPrioritizationFees' ,
510
- args ,
511
- ) ) as RpcResponse ;
508
+ const response = ( await rpcRequest (
509
+ 'getRecentPrioritizationFees' ,
510
+ args ,
511
+ ) ) as RpcResponse ;
512
512
513
- if ( response . error ) {
514
- throw new Error ( response . error ) ;
515
- }
513
+ if ( response . error ) {
514
+ // Allow the error to propagate so the caller can handle it and fall-back if needed
515
+ throw new Error ( response . error ) ;
516
+ }
516
517
517
- const recentPrioritizationFees =
518
- response . result as RecentPrioritizationFees [ ] ;
518
+ const recentPrioritizationFees =
519
+ response . result as RecentPrioritizationFees [ ] ;
519
520
520
- if ( recentPrioritizationFees . length > 0 ) {
521
- const sortedFees = recentPrioritizationFees . sort (
522
- ( a , b ) => a . prioritizationFee - b . prioritizationFee ,
523
- ) ;
521
+ if ( recentPrioritizationFees . length > 0 ) {
522
+ const sortedFees = recentPrioritizationFees . sort (
523
+ ( a , b ) => a . prioritizationFee - b . prioritizationFee ,
524
+ ) ;
524
525
525
- // Calculate the median
526
- const half = Math . floor ( sortedFees . length / 2 ) ;
527
- if ( sortedFees . length % 2 === 0 ) {
528
- fee = Math . floor (
529
- ( sortedFees [ half - 1 ] ! . prioritizationFee +
530
- sortedFees [ half ] ! . prioritizationFee ) /
531
- 2 ,
532
- ) ;
533
- } else {
534
- fee = sortedFees [ half ] ! . prioritizationFee ;
535
- }
526
+ // Calculate the median
527
+ const half = Math . floor ( sortedFees . length / 2 ) ;
528
+ if ( sortedFees . length % 2 === 0 ) {
529
+ fee = Math . floor (
530
+ ( sortedFees [ half - 1 ] ! . prioritizationFee +
531
+ sortedFees [ half ] ! . prioritizationFee ) /
532
+ 2 ,
533
+ ) ;
534
+ } else {
535
+ fee = sortedFees [ half ] ! . prioritizationFee ;
536
+ }
536
537
537
- if ( multiple > 0 ) {
538
- fee *= multiple ;
539
- }
538
+ if ( multiple > 0 ) {
539
+ fee *= multiple ;
540
540
}
541
- } catch ( e ) {
542
- console . error ( 'Error fetching Triton One Solana recent fees' , e ) ;
543
541
}
544
542
545
543
// Bound the return value by the parameters passed
0 commit comments