@@ -441,7 +441,7 @@ export class PythStakingClient {
441
441
442
442
// anchor does not calculate the correct pda for other programs
443
443
// therefore we need to manually calculate the pdas
444
- return Promise . all (
444
+ const advanceDelegationRecordInstructions = await Promise . all (
445
445
publishers . map ( ( { pubkey, stakeAccount } ) =>
446
446
this . integrityPoolProgram . methods
447
447
. advanceDelegationRecord ( )
@@ -458,16 +458,37 @@ export class PythStakingClient {
458
458
) ,
459
459
} )
460
460
. instruction ( ) ,
461
- ) ,
462
- ) ;
461
+ ) ) ;
462
+
463
+ const mergePositionsInstruction = await Promise . all (
464
+ publishers . map ( ( { pubkey } ) =>
465
+ this . integrityPoolProgram . methods
466
+ . mergeDelegationPositions ( )
467
+ . accounts ( {
468
+ owner : this . wallet . publicKey ,
469
+ publisher : pubkey ,
470
+ stakeAccountPositions,
471
+ } )
472
+ . instruction ( ) ,
473
+ ) ,
474
+ ) ;
475
+
476
+ return {
477
+ advanceDelegationRecordInstructions,
478
+ mergePositionsInstruction,
479
+ } ;
463
480
}
464
481
465
482
public async advanceDelegationRecord ( stakeAccountPositions : PublicKey ) {
466
483
const instructions = await this . getAdvanceDelegationRecordInstructions (
467
484
stakeAccountPositions ,
468
485
) ;
469
486
470
- return sendTransaction ( instructions , this . connection , this . wallet ) ;
487
+
488
+ return sendTransaction ( [
489
+ ...instructions . advanceDelegationRecordInstructions ,
490
+ ...instructions . mergePositionsInstruction ,
491
+ ] , this . connection , this . wallet ) ;
471
492
}
472
493
473
494
public async getClaimableRewards ( stakeAccountPositions : PublicKey ) {
@@ -477,7 +498,7 @@ export class PythStakingClient {
477
498
478
499
let totalRewards = 0n ;
479
500
480
- for ( const instruction of instructions ) {
501
+ for ( const instruction of instructions . advanceDelegationRecordInstructions ) {
481
502
const tx = new Transaction ( ) . add ( instruction ) ;
482
503
tx . feePayer = this . wallet . publicKey ;
483
504
const res = await this . connection . simulateTransaction ( tx ) ;
@@ -488,7 +509,6 @@ export class PythStakingClient {
488
509
const buffer = Buffer . from ( val , "base64" ) . reverse ( ) ;
489
510
totalRewards += BigInt ( "0x" + buffer . toString ( "hex" ) ) ;
490
511
}
491
-
492
512
return totalRewards ;
493
513
}
494
514
}
0 commit comments