Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions VoteStakeRegistry/actions/getClawbackInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export const getClawbackInstruction = async ({
)
const { voter } = getVoterPDA(registrar, voterWalletAddress, clientProgramId)

const tokenProgram = client?.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK ?
TOKEN_2022_PROGRAM_ID :
TOKEN_PROGRAM_ID

const mintInfo = await client?.program.provider.connection.getAccountInfo(grantMintPk)
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID)
? TOKEN_2022_PROGRAM_ID
: TOKEN_PROGRAM_ID

const voterATAPk = await Token.getAssociatedTokenAddress(
ASSOCIATED_TOKEN_PROGRAM_ID,
tokenProgram,
Expand Down
7 changes: 4 additions & 3 deletions VoteStakeRegistry/actions/getGrantInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export const getGrantInstruction = async ({
const systemProgram = SystemProgram.programId
const clientProgramId = client!.program.programId

const tokenProgram = client?.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK ?
TOKEN_2022_PROGRAM_ID :
TOKEN_PROGRAM_ID
const mintInfo = await client?.program.provider.connection.getAccountInfo(grantMintPk)
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID)
? TOKEN_2022_PROGRAM_ID
: TOKEN_PROGRAM_ID

const { registrar } = getRegistrarPDA(
realmPk,
Expand Down
4 changes: 2 additions & 2 deletions VoteStakeRegistry/actions/voteRegistryLockDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LockupType } from 'VoteStakeRegistry/sdk/accounts'
import { withCreateNewDeposit } from '../sdk/withCreateNewDeposit'
import { getPeriod } from 'VoteStakeRegistry/tools/deposits'
import { VsrClient } from 'VoteStakeRegistry/sdk/client'
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token-new'
import { CUSTOM_BIO_VSR_PLUGIN_PK } from '@constants/plugins'

export const voteRegistryLockDeposit = async ({
rpcContext,
Expand Down Expand Up @@ -106,7 +106,7 @@ export const voteRegistryLockDeposit = async ({
})
.instruction()

if (tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
if (client.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK) {
depositInstruction.keys.splice(3, 0, {
pubkey: mintPk,
isSigner: false,
Expand Down
11 changes: 8 additions & 3 deletions VoteStakeRegistry/sdk/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import BN from 'bn.js'
import { fetchVotingPower } from '@hooks/queries/plugins/vsr'
import { getMint, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token-new'
import { getAssociatedTokenAddressSync } from '@solana/spl-token-new'
import { MintInfo, u64 } from '@solana/spl-token'
import { MintInfo, TOKEN_PROGRAM_ID, u64 } from '@solana/spl-token'

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

if (registrarAccount.votingMints.length) {
const depositMint = registrarAccount.votingMints[0].mint
const mintInfo = await this.program.provider.connection.getAccountInfo(depositMint)
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID)
? TOKEN_2022_PROGRAM_ID
: TOKEN_PROGRAM_ID

const ata = getAssociatedTokenAddressSync(
depositMint, owner, true, TOKEN_2022_PROGRAM_ID
depositMint, owner, true, tokenProgram
)

const account = await this.program.provider.connection.getAccountInfo(ata)
const mintAccount = await getMint(this.program.provider.connection, depositMint, undefined, TOKEN_2022_PROGRAM_ID)
const mintAccount = await getMint(this.program.provider.connection, depositMint, undefined, tokenProgram)

return {
pubkey: ata,
Expand Down
3 changes: 2 additions & 1 deletion VoteStakeRegistry/sdk/withVoteRegistryDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LockupType } from 'VoteStakeRegistry/sdk/accounts'
import { withCreateNewDeposit } from './withCreateNewDeposit'
import { VsrClient } from './client'
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token-new'
import { CUSTOM_BIO_VSR_PLUGIN_PK } from '@constants/plugins'

export const withVoteRegistryDeposit = async ({
instructions,
Expand Down Expand Up @@ -65,7 +66,7 @@ export const withVoteRegistryDeposit = async ({
})
.instruction()

if (tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
if (client.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK) {
depositInstruction.keys.splice(3, 0, {
pubkey: mintPk,
isSigner: false,
Expand Down
7 changes: 3 additions & 4 deletions VoteStakeRegistry/sdk/withVoteRegistryWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ export const withVoteRegistryWithdraw = async ({
}
const clientProgramId = client!.program.programId

const tokenProgram = clientProgramId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK ?
TOKEN_2022_PROGRAM_ID :
TOKEN_PROGRAM_ID
const mintInfo = await client.program.provider.connection.getAccountInfo(mintPk)
const tokenProgram = mintInfo?.owner.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID

const { registrar } = getRegistrarPDA(
realmPk,
Expand Down Expand Up @@ -122,7 +121,7 @@ export const withVoteRegistryWithdraw = async ({
})
.instruction()

if (tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
if (client.program.programId.toBase58() === CUSTOM_BIO_VSR_PLUGIN_PK) {
withdrawInstruction.keys.splice(6, 0, {
pubkey: mintPk,
isSigner: false,
Expand Down
Loading