Skip to content

Commit 83ce7a5

Browse files
add merge positions (#1913)
1 parent 525ad19 commit 83ce7a5

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

governance/pyth_staking_sdk/src/pyth-staking-client.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export class PythStakingClient {
441441

442442
// anchor does not calculate the correct pda for other programs
443443
// therefore we need to manually calculate the pdas
444-
return Promise.all(
444+
const advanceDelegationRecordInstructions = await Promise.all(
445445
publishers.map(({ pubkey, stakeAccount }) =>
446446
this.integrityPoolProgram.methods
447447
.advanceDelegationRecord()
@@ -458,16 +458,37 @@ export class PythStakingClient {
458458
),
459459
})
460460
.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+
};
463480
}
464481

465482
public async advanceDelegationRecord(stakeAccountPositions: PublicKey) {
466483
const instructions = await this.getAdvanceDelegationRecordInstructions(
467484
stakeAccountPositions,
468485
);
469486

470-
return sendTransaction(instructions, this.connection, this.wallet);
487+
488+
return sendTransaction([
489+
...instructions.advanceDelegationRecordInstructions,
490+
...instructions.mergePositionsInstruction,
491+
], this.connection, this.wallet);
471492
}
472493

473494
public async getClaimableRewards(stakeAccountPositions: PublicKey) {
@@ -477,7 +498,7 @@ export class PythStakingClient {
477498

478499
let totalRewards = 0n;
479500

480-
for (const instruction of instructions) {
501+
for (const instruction of instructions.advanceDelegationRecordInstructions) {
481502
const tx = new Transaction().add(instruction);
482503
tx.feePayer = this.wallet.publicKey;
483504
const res = await this.connection.simulateTransaction(tx);
@@ -488,7 +509,6 @@ export class PythStakingClient {
488509
const buffer = Buffer.from(val, "base64").reverse();
489510
totalRewards += BigInt("0x" + buffer.toString("hex"));
490511
}
491-
492512
return totalRewards;
493513
}
494514
}

0 commit comments

Comments
 (0)