@@ -172,7 +172,9 @@ export class PythStakingClient {
172
172
publisher : PublicKey ,
173
173
) {
174
174
return this . integrityPoolProgram . account . delegationRecord
175
- . fetch ( getDelegationRecordAddress ( stakeAccountPositions , publisher ) )
175
+ . fetchNullable (
176
+ getDelegationRecordAddress ( stakeAccountPositions , publisher ) ,
177
+ )
176
178
. then ( ( record ) => convertBNToBigInt ( record ) ) ;
177
179
}
178
180
@@ -685,10 +687,23 @@ export class PythStakingClient {
685
687
) ,
686
688
) ;
687
689
690
+ const delegationRecords = await Promise . all (
691
+ publishers . map ( ( { pubkey } ) =>
692
+ this . getDelegationRecord ( stakeAccountPositions , pubkey ) ,
693
+ ) ,
694
+ ) ;
695
+
696
+ const currentEpoch = await getCurrentEpoch ( this . connection ) ;
697
+
698
+ // Filter out delegationRecord that are up to date
699
+ const filteredPublishers = publishers . filter ( ( _ , index ) => {
700
+ return ! ( delegationRecords [ index ] ?. lastEpoch === currentEpoch ) ;
701
+ } ) ;
702
+
688
703
// anchor does not calculate the correct pda for other programs
689
704
// therefore we need to manually calculate the pdas
690
705
const advanceDelegationRecordInstructions = await Promise . all (
691
- publishers . map ( ( { pubkey, stakeAccount } ) =>
706
+ filteredPublishers . map ( ( { pubkey, stakeAccount } ) =>
692
707
this . integrityPoolProgram . methods
693
708
. advanceDelegationRecord ( )
694
709
. accountsPartial ( {
@@ -761,19 +776,19 @@ export class PythStakingClient {
761
776
totalRewards += BigInt ( "0x" + buffer . toString ( "hex" ) ) ;
762
777
}
763
778
764
- const delegationRecords = await Promise . allSettled (
779
+ const delegationRecords = await Promise . all (
765
780
instructions . publishers . map ( ( { pubkey } ) =>
766
781
this . getDelegationRecord ( stakeAccountPositions , pubkey ) ,
767
782
) ,
768
783
) ;
769
784
770
785
let lowestEpoch : bigint | undefined ;
771
786
for ( const record of delegationRecords ) {
772
- if ( record . status === "fulfilled" ) {
773
- const { lastEpoch } = record . value ;
774
- if ( lowestEpoch === undefined || lastEpoch < lowestEpoch ) {
775
- lowestEpoch = lastEpoch ;
776
- }
787
+ if (
788
+ record !== null &&
789
+ ( lowestEpoch === undefined || record . lastEpoch < lowestEpoch )
790
+ ) {
791
+ lowestEpoch = record . lastEpoch ;
777
792
}
778
793
}
779
794
0 commit comments