@@ -27,7 +27,12 @@ import {
27
27
import { NotSupported , TransactionType } from '@bitgo/sdk-core' ;
28
28
import { coins , SolCoin } from '@bitgo/statics' ;
29
29
import assert from 'assert' ;
30
- import { InstructionBuilderTypes , ValidInstructionTypesEnum , walletInitInstructionIndexes } from './constants' ;
30
+ import {
31
+ InstructionBuilderTypes ,
32
+ JITO_STAKE_POOL_ADDRESS ,
33
+ ValidInstructionTypesEnum ,
34
+ walletInitInstructionIndexes ,
35
+ } from './constants' ;
31
36
import {
32
37
AtaClose ,
33
38
AtaInit ,
@@ -47,6 +52,8 @@ import {
47
52
SetPriorityFee ,
48
53
} from './iface' ;
49
54
import { getInstructionType } from './utils' ;
55
+ import { DepositSolParams } from '@solana/spl-stake-pool' ;
56
+ import { decodeDepositSol } from './jitoStakePoolOperations' ;
50
57
51
58
/**
52
59
* Construct instructions params from Solana instructions
@@ -303,6 +310,14 @@ function parseSendInstructions(
303
310
return instructionData ;
304
311
}
305
312
313
+ function stakingInstructionsIsMarinade ( si : StakingInstructions ) : boolean {
314
+ return ! ! ( si . delegate === undefined && si . depositSol === undefined ) ;
315
+ }
316
+
317
+ function stakingInstructionsIsJito ( si : StakingInstructions ) : boolean {
318
+ return ! ! ( si . delegate === undefined && si . depositSol ?. stakePool . toString ( ) === JITO_STAKE_POOL_ADDRESS ) ;
319
+ }
320
+
306
321
/**
307
322
* Parses Solana instructions to create staking tx and delegate tx instructions params
308
323
* Only supports Nonce, StakingActivate and Memo Solana instructions
@@ -312,8 +327,8 @@ function parseSendInstructions(
312
327
*/
313
328
function parseStakingActivateInstructions (
314
329
instructions : TransactionInstruction [ ]
315
- ) : Array < Nonce | StakingActivate | Memo > {
316
- const instructionData : Array < Nonce | StakingActivate | Memo > = [ ] ;
330
+ ) : Array < Nonce | StakingActivate | Memo | AtaInit > {
331
+ const instructionData : Array < Nonce | StakingActivate | Memo | AtaInit > = [ ] ;
317
332
const stakingInstructions = { } as StakingInstructions ;
318
333
for ( const instruction of instructions ) {
319
334
const type = getInstructionType ( instruction ) ;
@@ -346,21 +361,48 @@ function parseStakingActivateInstructions(
346
361
case ValidInstructionTypesEnum . StakingDelegate :
347
362
stakingInstructions . delegate = StakeInstruction . decodeDelegate ( instruction ) ;
348
363
break ;
364
+
365
+ case ValidInstructionTypesEnum . DepositSol :
366
+ stakingInstructions . depositSol = decodeDepositSol ( instruction ) ;
367
+ break ;
368
+
369
+ case ValidInstructionTypesEnum . InitializeAssociatedTokenAccount :
370
+ instructionData . push ( {
371
+ type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
372
+ params : {
373
+ mintAddress : instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ,
374
+ ataAddress : instruction . keys [ ataInitInstructionKeysIndexes . ATAAddress ] . pubkey . toString ( ) ,
375
+ ownerAddress : instruction . keys [ ataInitInstructionKeysIndexes . OwnerAddress ] . pubkey . toString ( ) ,
376
+ payerAddress : instruction . keys [ ataInitInstructionKeysIndexes . PayerAddress ] . pubkey . toString ( ) ,
377
+ tokenName : findTokenName ( instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ) ,
378
+ } ,
379
+ } ) ;
380
+ break ;
349
381
}
350
382
}
351
383
352
384
validateStakingInstructions ( stakingInstructions ) ;
385
+
353
386
const stakingActivate : StakingActivate = {
354
387
type : InstructionBuilderTypes . StakingActivate ,
355
388
params : {
356
- fromAddress : stakingInstructions . create ?. fromPubkey . toString ( ) || '' ,
357
- stakingAddress : stakingInstructions . initialize ?. stakePubkey . toString ( ) || '' ,
358
- amount : stakingInstructions . create ?. lamports . toString ( ) || '' ,
389
+ fromAddress :
390
+ stakingInstructions . create ?. fromPubkey . toString ( ) ||
391
+ stakingInstructions . depositSol ?. fundingAccount . toString ( ) ||
392
+ '' ,
393
+ stakingAddress :
394
+ stakingInstructions . initialize ?. stakePubkey . toString ( ) ||
395
+ stakingInstructions . depositSol ?. stakePool . toString ( ) ||
396
+ '' ,
397
+ amount :
398
+ stakingInstructions . create ?. lamports . toString ( ) || stakingInstructions . depositSol ?. lamports . toString ( ) || '' ,
359
399
validator :
360
400
stakingInstructions . delegate ?. votePubkey . toString ( ) ||
361
401
stakingInstructions . initialize ?. authorized . staker . toString ( ) ||
402
+ stakingInstructions . depositSol ?. stakePool . toString ( ) ||
362
403
'' ,
363
- isMarinade : stakingInstructions . delegate === undefined ,
404
+ isMarinade : stakingInstructionsIsMarinade ( stakingInstructions ) ,
405
+ isJito : stakingInstructionsIsJito ( stakingInstructions ) ,
364
406
} ,
365
407
} ;
366
408
instructionData . push ( stakingActivate ) ;
@@ -413,22 +455,23 @@ interface StakingInstructions {
413
455
initialize ?: InitializeStakeParams ;
414
456
delegate ?: DelegateStakeParams ;
415
457
authorize ?: AuthorizeStakeParams [ ] ;
458
+ depositSol ?: DepositSolParams ;
416
459
}
417
460
418
461
function validateStakingInstructions ( stakingInstructions : StakingInstructions ) {
419
- if ( ! stakingInstructions . create ) {
420
- throw new NotSupported ( 'Invalid staking activate transaction, missing create stake account instruction' ) ;
421
- }
422
-
423
- if ( ! stakingInstructions . initialize && stakingInstructions . delegate ) {
424
- return ;
425
- } else if ( ! stakingInstructions . delegate && stakingInstructions . initialize ) {
426
- return ;
427
- } else if ( ! stakingInstructions . delegate && ! stakingInstructions . initialize ) {
428
- // If both are missing something is wrong
429
- throw new NotSupported (
430
- 'Invalid staking activate transaction, missing initialize stake account/delegate instruction'
431
- ) ;
462
+ if ( stakingInstructionsIsJito ( stakingInstructions ) ) {
463
+ if ( ! stakingInstructions . depositSol ) {
464
+ throw new NotSupported ( 'Invalid staking activate transaction, missing deposit sol instruction' ) ;
465
+ }
466
+ } else {
467
+ if ( ! stakingInstructions . create ) {
468
+ throw new NotSupported ( 'Invalid staking activate transaction, missing create stake account instruction' ) ;
469
+ }
470
+ if ( ! stakingInstructions . delegate && ! stakingInstructions . initialize ) {
471
+ throw new NotSupported (
472
+ 'Invalid staking activate transaction, missing initialize stake account/delegate instruction'
473
+ ) ;
474
+ }
432
475
}
433
476
}
434
477
@@ -776,6 +819,9 @@ function parseAtaInitInstructions(
776
819
} ;
777
820
instructionData . push ( ataInit ) ;
778
821
break ;
822
+ case ValidInstructionTypesEnum . DepositSol :
823
+ // AtaInit is a part of spl-stake-pool's depositSol process
824
+ break ;
779
825
default :
780
826
throw new NotSupported (
781
827
'Invalid transaction, instruction type not supported: ' + getInstructionType ( instruction )
0 commit comments