diff --git a/governance/pyth_staking_sdk/src/pyth-staking-client.ts b/governance/pyth_staking_sdk/src/pyth-staking-client.ts index 68ecab1b8d..79e21fbdf2 100644 --- a/governance/pyth_staking_sdk/src/pyth-staking-client.ts +++ b/governance/pyth_staking_sdk/src/pyth-staking-client.ts @@ -172,9 +172,7 @@ export class PythStakingClient { publisher: PublicKey, ) { return this.integrityPoolProgram.account.delegationRecord - .fetchNullable( - getDelegationRecordAddress(stakeAccountPositions, publisher), - ) + .fetch(getDelegationRecordAddress(stakeAccountPositions, publisher)) .then((record) => convertBNToBigInt(record)); } @@ -687,23 +685,10 @@ export class PythStakingClient { ), ); - const delegationRecords = await Promise.all( - publishers.map(({ pubkey }) => - this.getDelegationRecord(stakeAccountPositions, pubkey), - ), - ); - - const currentEpoch = await getCurrentEpoch(this.connection); - - // Filter out delegationRecord that are up to date - const filteredPublishers = publishers.filter((_, index) => { - return !(delegationRecords[index]?.lastEpoch === currentEpoch); - }); - // anchor does not calculate the correct pda for other programs // therefore we need to manually calculate the pdas const advanceDelegationRecordInstructions = await Promise.all( - filteredPublishers.map(({ pubkey, stakeAccount }) => + publishers.map(({ pubkey, stakeAccount }) => this.integrityPoolProgram.methods .advanceDelegationRecord() .accountsPartial({ @@ -776,7 +761,7 @@ export class PythStakingClient { totalRewards += BigInt("0x" + buffer.toString("hex")); } - const delegationRecords = await Promise.all( + const delegationRecords = await Promise.allSettled( instructions.publishers.map(({ pubkey }) => this.getDelegationRecord(stakeAccountPositions, pubkey), ), @@ -784,11 +769,11 @@ export class PythStakingClient { let lowestEpoch: bigint | undefined; for (const record of delegationRecords) { - if ( - record !== null && - (lowestEpoch === undefined || record.lastEpoch < lowestEpoch) - ) { - lowestEpoch = record.lastEpoch; + if (record.status === "fulfilled") { + const { lastEpoch } = record.value; + if (lowestEpoch === undefined || lastEpoch < lowestEpoch) { + lowestEpoch = lastEpoch; + } } }