@@ -214,10 +214,17 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
214
214
// Section: Transaction construction
215
215
//
216
216
217
- computeUnitLimit , _ := compute_budget .DecompileSetComputeUnitLimitIxnData (jupiterSwapIxns .ComputeBudgetInstructions [0 ].Data )
217
+ var computeUnitLimit uint32
218
+ var computeUnitPrice uint64
219
+ if len (jupiterSwapIxns .ComputeBudgetInstructions ) == 2 {
220
+ computeUnitLimit , _ = compute_budget .DecompileSetComputeUnitLimitIxnData (jupiterSwapIxns .ComputeBudgetInstructions [0 ].Data )
218
221
219
- computeUnitPrice , _ := compute_budget .DecompileSetComputeUnitPriceIxnData (jupiterSwapIxns .ComputeBudgetInstructions [1 ].Data )
220
- computeUnitPrice = uint64 (s .conf .swapPriorityFeeMultiple .Get (ctx ) * float64 (computeUnitPrice ))
222
+ computeUnitPrice , _ = compute_budget .DecompileSetComputeUnitPriceIxnData (jupiterSwapIxns .ComputeBudgetInstructions [1 ].Data )
223
+ computeUnitPrice = uint64 (s .conf .swapPriorityFeeMultiple .Get (ctx ) * float64 (computeUnitPrice ))
224
+ } else {
225
+ computeUnitLimit = 1_400_000
226
+ computeUnitPrice = 10_000
227
+ }
221
228
222
229
swapNonce , err := common .NewRandomAccount ()
223
230
if err != nil {
@@ -439,8 +446,8 @@ func (s *transactionServer) validateSwap(
439
446
// Part 1: Expected instructions sanity check
440
447
//
441
448
442
- if len (ixns .ComputeBudgetInstructions ) != 2 {
443
- return newSwapValidationError ("expected two compute budget instructions" )
449
+ if len (ixns .ComputeBudgetInstructions ) != 0 && len ( ixns . ComputeBudgetInstructions ) != 2 {
450
+ return newSwapValidationError ("expected zero or two compute budget instructions" )
444
451
}
445
452
446
453
if ixns .TokenLedgerInstruction != nil || ixns .CleanupInstruction != nil {
@@ -451,20 +458,22 @@ func (s *transactionServer) validateSwap(
451
458
// Part 2: Compute budget instructions
452
459
//
453
460
454
- if ! bytes .Equal (ixns .ComputeBudgetInstructions [0 ].Program , compute_budget .ProgramKey ) || ! bytes .Equal (ixns .ComputeBudgetInstructions [1 ].Program , compute_budget .ProgramKey ) {
455
- return newSwapValidationError ("invalid ComputeBudget program key" )
456
- }
461
+ if len (ixns .ComputeBudgetInstructions ) > 0 {
462
+ if ! bytes .Equal (ixns .ComputeBudgetInstructions [0 ].Program , compute_budget .ProgramKey ) || ! bytes .Equal (ixns .ComputeBudgetInstructions [1 ].Program , compute_budget .ProgramKey ) {
463
+ return newSwapValidationError ("invalid ComputeBudget program key" )
464
+ }
457
465
458
- if len (ixns .ComputeBudgetInstructions [0 ].Accounts ) != 0 || len (ixns .ComputeBudgetInstructions [1 ].Accounts ) != 0 {
459
- return newSwapValidationError ("invalid ComputeBudget instruction accounts" )
460
- }
466
+ if len (ixns .ComputeBudgetInstructions [0 ].Accounts ) != 0 || len (ixns .ComputeBudgetInstructions [1 ].Accounts ) != 0 {
467
+ return newSwapValidationError ("invalid ComputeBudget instruction accounts" )
468
+ }
461
469
462
- if _ , err := compute_budget .DecompileSetComputeUnitLimitIxnData (ixns .ComputeBudgetInstructions [0 ].Data ); err != nil {
463
- return newSwapValidationErrorf ("invalid ComputeBudget::SetComputeUnitLimit instruction data: %s" , err .Error ())
464
- }
470
+ if _ , err := compute_budget .DecompileSetComputeUnitLimitIxnData (ixns .ComputeBudgetInstructions [0 ].Data ); err != nil {
471
+ return newSwapValidationErrorf ("invalid ComputeBudget::SetComputeUnitLimit instruction data: %s" , err .Error ())
472
+ }
465
473
466
- if _ , err := compute_budget .DecompileSetComputeUnitPriceIxnData (ixns .ComputeBudgetInstructions [1 ].Data ); err != nil {
467
- return newSwapValidationErrorf ("invalid ComputeBudget::SetComputeUnitPrice instruction data: %s" , err .Error ())
474
+ if _ , err := compute_budget .DecompileSetComputeUnitPriceIxnData (ixns .ComputeBudgetInstructions [1 ].Data ); err != nil {
475
+ return newSwapValidationErrorf ("invalid ComputeBudget::SetComputeUnitPrice instruction data: %s" , err .Error ())
476
+ }
468
477
}
469
478
470
479
//
0 commit comments