Skip to content

Commit c131a54

Browse files
authored
fix bio plugin (#200)
1 parent a9159c5 commit c131a54

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

VoteStakeRegistry/actions/getClawbackInstruction.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ export const getClawbackInstruction = async ({
3838
)
3939
const { voter } = getVoterPDA(registrar, voterWalletAddress, clientProgramId)
4040

41-
const tokenProgram = client?.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK ?
42-
TOKEN_2022_PROGRAM_ID :
43-
TOKEN_PROGRAM_ID
44-
41+
const mintInfo = await client?.program.provider.connection.getAccountInfo(grantMintPk)
42+
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID)
43+
? TOKEN_2022_PROGRAM_ID
44+
: TOKEN_PROGRAM_ID
45+
4546
const voterATAPk = await Token.getAssociatedTokenAddress(
4647
ASSOCIATED_TOKEN_PROGRAM_ID,
4748
tokenProgram,

VoteStakeRegistry/actions/getGrantInstruction.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ export const getGrantInstruction = async ({
5151
const systemProgram = SystemProgram.programId
5252
const clientProgramId = client!.program.programId
5353

54-
const tokenProgram = client?.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK ?
55-
TOKEN_2022_PROGRAM_ID :
56-
TOKEN_PROGRAM_ID
54+
const mintInfo = await client?.program.provider.connection.getAccountInfo(grantMintPk)
55+
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID)
56+
? TOKEN_2022_PROGRAM_ID
57+
: TOKEN_PROGRAM_ID
5758

5859
const { registrar } = getRegistrarPDA(
5960
realmPk,

VoteStakeRegistry/actions/voteRegistryLockDeposit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { LockupType } from 'VoteStakeRegistry/sdk/accounts'
1212
import { withCreateNewDeposit } from '../sdk/withCreateNewDeposit'
1313
import { getPeriod } from 'VoteStakeRegistry/tools/deposits'
1414
import { VsrClient } from 'VoteStakeRegistry/sdk/client'
15-
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token-new'
15+
import { CUSTOM_BIO_VSR_PLUGIN_PK } from '@constants/plugins'
1616

1717
export const voteRegistryLockDeposit = async ({
1818
rpcContext,
@@ -106,7 +106,7 @@ export const voteRegistryLockDeposit = async ({
106106
})
107107
.instruction()
108108

109-
if (tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
109+
if (client.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK) {
110110
depositInstruction.keys.splice(3, 0, {
111111
pubkey: mintPk,
112112
isSigner: false,

VoteStakeRegistry/sdk/client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import BN from 'bn.js'
1414
import { fetchVotingPower } from '@hooks/queries/plugins/vsr'
1515
import { getMint, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token-new'
1616
import { getAssociatedTokenAddressSync } from '@solana/spl-token-new'
17-
import { MintInfo, u64 } from '@solana/spl-token'
17+
import { MintInfo, TOKEN_PROGRAM_ID, u64 } from '@solana/spl-token'
1818

1919
export const DEFAULT_VSR_ID = new web3.PublicKey(
2020
'vsr2nfGVNHmSY8uxoBGqq8AQbwz3JwaEaHqGbsTPXqQ',
@@ -180,12 +180,17 @@ export class VsrClient extends Client<typeof IDL> {
180180

181181
if (registrarAccount.votingMints.length) {
182182
const depositMint = registrarAccount.votingMints[0].mint
183+
const mintInfo = await this.program.provider.connection.getAccountInfo(depositMint)
184+
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID)
185+
? TOKEN_2022_PROGRAM_ID
186+
: TOKEN_PROGRAM_ID
187+
183188
const ata = getAssociatedTokenAddressSync(
184-
depositMint, owner, true, TOKEN_2022_PROGRAM_ID
189+
depositMint, owner, true, tokenProgram
185190
)
186191

187192
const account = await this.program.provider.connection.getAccountInfo(ata)
188-
const mintAccount = await getMint(this.program.provider.connection, depositMint, undefined, TOKEN_2022_PROGRAM_ID)
193+
const mintAccount = await getMint(this.program.provider.connection, depositMint, undefined, tokenProgram)
189194

190195
return {
191196
pubkey: ata,

VoteStakeRegistry/sdk/withVoteRegistryDeposit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LockupType } from 'VoteStakeRegistry/sdk/accounts'
44
import { withCreateNewDeposit } from './withCreateNewDeposit'
55
import { VsrClient } from './client'
66
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token-new'
7+
import { CUSTOM_BIO_VSR_PLUGIN_PK } from '@constants/plugins'
78

89
export const withVoteRegistryDeposit = async ({
910
instructions,
@@ -65,7 +66,7 @@ export const withVoteRegistryDeposit = async ({
6566
})
6667
.instruction()
6768

68-
if (tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
69+
if (client.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK) {
6970
depositInstruction.keys.splice(3, 0, {
7071
pubkey: mintPk,
7172
isSigner: false,

VoteStakeRegistry/sdk/withVoteRegistryWithdraw.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ export const withVoteRegistryWithdraw = async ({
5050
}
5151
const clientProgramId = client!.program.programId
5252

53-
const tokenProgram = clientProgramId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK ?
54-
TOKEN_2022_PROGRAM_ID :
55-
TOKEN_PROGRAM_ID
53+
const mintInfo = await client.program.provider.connection.getAccountInfo(mintPk)
54+
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID
5655

5756
const { registrar } = getRegistrarPDA(
5857
realmPk,
@@ -122,7 +121,7 @@ export const withVoteRegistryWithdraw = async ({
122121
})
123122
.instruction()
124123

125-
if (tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
124+
if (client.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK) {
126125
withdrawInstruction.keys.splice(6, 0, {
127126
pubkey: mintPk,
128127
isSigner: false,

0 commit comments

Comments
 (0)