Skip to content
Merged
Changes from all 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
92 changes: 71 additions & 21 deletions governance/pyth_staking_sdk/src/pyth-staking-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,29 @@ export class PythStakingClient {
stakeAccountPositions: PublicKey,
amount: bigint,
) {
const instruction = await this.stakingProgram.methods
.createPosition(
{
voting: {},
},
new BN(amount.toString()),
)
.accounts({
stakeAccountPositions,
})
.instruction();
const instructions = [];

return sendTransaction([instruction], this.connection, this.wallet);
if (!(await this.hasJoinedDaoLlc(stakeAccountPositions))) {
instructions.push(
await this.getJoinDaoLlcInstruction(stakeAccountPositions),
);
}

instructions.push(
await this.stakingProgram.methods
.createPosition(
{
voting: {},
},
new BN(amount.toString()),
)
.accounts({
stakeAccountPositions,
})
.instruction(),
);

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

public async unstakeFromGovernance(
Expand Down Expand Up @@ -532,16 +542,26 @@ export class PythStakingClient {
publisher: PublicKey,
amount: bigint,
) {
const instruction = await this.integrityPoolProgram.methods
.delegate(convertBigIntToBN(amount))
.accounts({
owner: this.wallet.publicKey,
publisher,
stakeAccountPositions,
})
.instruction();
const instructions = [];

return sendTransaction([instruction], this.connection, this.wallet);
if (!(await this.hasJoinedDaoLlc(stakeAccountPositions))) {
instructions.push(
await this.getJoinDaoLlcInstruction(stakeAccountPositions),
);
}

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

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

public async getUnlockSchedule(
Expand Down Expand Up @@ -821,6 +841,36 @@ export class PythStakingClient {
.instruction();
}

public async hasJoinedDaoLlc(
stakeAccountPositions: PublicKey,
): Promise<boolean> {
const config = await this.getGlobalConfig();
const stakeAccountMetadataAddress = getStakeAccountMetadataAddress(
stakeAccountPositions,
);
const stakeAccountMetadata =
await this.stakingProgram.account.stakeAccountMetadataV2.fetch(
stakeAccountMetadataAddress,
);

return (
JSON.stringify(stakeAccountMetadata.signedAgreementHash) ===
JSON.stringify(config.agreementHash)
);
}

public async getJoinDaoLlcInstruction(
stakeAccountPositions: PublicKey,
): Promise<TransactionInstruction> {
const config = await this.getGlobalConfig();
return this.stakingProgram.methods
.joinDaoLlc(config.agreementHash)
.accounts({
stakeAccountPositions,
})
.instruction();
}

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