@@ -24,6 +24,7 @@ import {
24
24
import { GOVERNANCE_ADDRESS , POSITIONS_ACCOUNT_SIZE } from "./constants" ;
25
25
import {
26
26
getConfigAddress ,
27
+ getDelegationRecordAddress ,
27
28
getPoolConfigAddress ,
28
29
getStakeAccountCustodyAddress ,
29
30
getStakeAccountMetadataAddress ,
@@ -36,7 +37,7 @@ import {
36
37
type StakeAccountPositions ,
37
38
} from "./types" ;
38
39
import { convertBigIntToBN , convertBNToBigInt } from "./utils/bn" ;
39
- import { getCurrentEpoch } from "./utils/clock" ;
40
+ import { epochToDate , getCurrentEpoch } from "./utils/clock" ;
40
41
import { extractPublisherData } from "./utils/pool" ;
41
42
import {
42
43
deserializeStakeAccountPositions ,
@@ -148,6 +149,17 @@ export class PythStakingClient {
148
149
) ;
149
150
}
150
151
152
+ public async getDelegationRecord (
153
+ stakeAccountPositions : PublicKey ,
154
+ publisher : PublicKey ,
155
+ ) {
156
+ const delegationRecord =
157
+ await this . integrityPoolProgram . account . delegationRecord . fetch (
158
+ getDelegationRecordAddress ( stakeAccountPositions , publisher ) ,
159
+ ) ;
160
+ return convertBNToBigInt ( delegationRecord ) ;
161
+ }
162
+
151
163
public async getStakeAccountCustody (
152
164
stakeAccountPositions : PublicKey ,
153
165
) : Promise < Account > {
@@ -573,6 +585,7 @@ export class PythStakingClient {
573
585
return {
574
586
advanceDelegationRecordInstructions,
575
587
mergePositionsInstruction,
588
+ publishers,
576
589
} ;
577
590
}
578
591
@@ -609,6 +622,24 @@ export class PythStakingClient {
609
622
const buffer = Buffer . from ( val , "base64" ) . reverse ( ) ;
610
623
totalRewards += BigInt ( "0x" + buffer . toString ( "hex" ) ) ;
611
624
}
612
- return totalRewards ;
625
+
626
+ const delegationRecords = await Promise . all (
627
+ instructions . publishers . map ( ( { pubkey } ) =>
628
+ this . getDelegationRecord ( stakeAccountPositions , pubkey ) ,
629
+ ) ,
630
+ ) ;
631
+
632
+ let lowestEpoch : bigint | undefined ;
633
+ for ( const record of delegationRecords ) {
634
+ if ( lowestEpoch === undefined || record . lastEpoch < lowestEpoch ) {
635
+ lowestEpoch = record . lastEpoch ;
636
+ }
637
+ }
638
+
639
+ return {
640
+ totalRewards,
641
+ expiry :
642
+ lowestEpoch === undefined ? undefined : epochToDate ( lowestEpoch + 52n ) ,
643
+ } ;
613
644
}
614
645
}
0 commit comments