Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 55 additions & 13 deletions governance/pyth_staking_sdk/src/pyth-staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,15 @@ export class PythStakingClient {
stakeAccountPositions: PublicKey,
amount: bigint,
) {
const instruction = await this.stakingProgram.methods
const instructions = [];
const joinDaoLlcInstruction = await this.getJoinDaoLlcInstructionIfNeeded(
stakeAccountPositions,
);
if (joinDaoLlcInstruction !== undefined) {
instructions.push(joinDaoLlcInstruction);
}

instructions.push(await this.stakingProgram.methods
.createPosition(
{
voting: {},
Expand All @@ -256,9 +264,9 @@ export class PythStakingClient {
.accounts({
stakeAccountPositions,
})
.instruction();
.instruction());

return sendTransaction([instruction], this.connection, this.wallet);
return sendTransaction(instructions, this.connection, this.wallet);
}

public async unstakeFromGovernance(
Expand Down Expand Up @@ -335,7 +343,7 @@ export class PythStakingClient {
.filter(
({ position }) =>
position.targetWithParameters.integrityPool?.publisher !==
undefined &&
undefined &&
position.targetWithParameters.integrityPool.publisher.equals(
publisher,
) &&
Expand Down Expand Up @@ -532,16 +540,24 @@ export class PythStakingClient {
publisher: PublicKey,
amount: bigint,
) {
const instruction = await this.integrityPoolProgram.methods
const instructions = [];
const joinDaoLlcInstruction = await this.getJoinDaoLlcInstructionIfNeeded(
stakeAccountPositions,
);
if (joinDaoLlcInstruction !== undefined) {
instructions.push(joinDaoLlcInstruction);
}

instructions.push(await this.integrityPoolProgram.methods
.delegate(convertBigIntToBN(amount))
.accounts({
owner: this.wallet.publicKey,
publisher,
stakeAccountPositions,
})
.instruction();
.instruction());

return sendTransaction([instruction], this.connection, this.wallet);
return sendTransaction(instructions, this.connection, this.wallet);
}

public async getUnlockSchedule(
Expand Down Expand Up @@ -810,17 +826,43 @@ export class PythStakingClient {
.remainingAccounts(
remainingAccount
? [
{
pubkey: remainingAccount,
isWritable: false,
isSigner: false,
},
]
{
pubkey: remainingAccount,
isWritable: false,
isSigner: false,
},
]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my formatter decided to do some stuff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does pnpm fix allow this?

: [],
)
.instruction();
}

public async getJoinDaoLlcInstructionIfNeeded(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make these separated functions.

hadJoinedDaoLlc and getJoinDaoLlcInstruction

Then you dont have to check if this the result of this function is undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

stakeAccountPositions: PublicKey
): Promise<TransactionInstruction | undefined> {

const config = await this.getGlobalConfig();
const stakeAccountMetadataAddress = getStakeAccountMetadataAddress(
stakeAccountPositions,
);
const stakeAccountMetadata =
await this.stakingProgram.account.stakeAccountMetadataV2.fetch(
stakeAccountMetadataAddress,
);

if (JSON.stringify(stakeAccountMetadata.signedAgreementHash) !== JSON.stringify(config.agreementHash)) {
return this.stakingProgram.methods
.joinDaoLlc(config.agreementHash)
.accounts({
stakeAccountPositions,
})
.instruction();
}
else {
return undefined;
}
}

public async getMainStakeAccount(owner?: PublicKey) {
const stakeAccountPositions = await this.getAllStakeAccountPositions(owner);
const currentEpoch = await getCurrentEpoch(this.connection);
Expand Down
Loading