-
Notifications
You must be signed in to change notification settings - Fork 302
fix: join llc before delegating #1978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: {}, | ||
|
|
@@ -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( | ||
|
|
@@ -335,7 +343,7 @@ export class PythStakingClient { | |
| .filter( | ||
| ({ position }) => | ||
| position.targetWithParameters.integrityPool?.publisher !== | ||
| undefined && | ||
| undefined && | ||
| position.targetWithParameters.integrityPool.publisher.equals( | ||
| publisher, | ||
| ) && | ||
|
|
@@ -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( | ||
|
|
@@ -810,17 +826,43 @@ export class PythStakingClient { | |
| .remainingAccounts( | ||
| remainingAccount | ||
| ? [ | ||
| { | ||
| pubkey: remainingAccount, | ||
| isWritable: false, | ||
| isSigner: false, | ||
| }, | ||
| ] | ||
| { | ||
| pubkey: remainingAccount, | ||
| isWritable: false, | ||
| isSigner: false, | ||
| }, | ||
| ] | ||
| : [], | ||
| ) | ||
| .instruction(); | ||
| } | ||
|
|
||
| public async getJoinDaoLlcInstructionIfNeeded( | ||
|
||
| 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); | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
pnpm fixallow this?