Skip to content

Commit

Permalink
fix uncached drift plugin queries (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
asktree committed May 14, 2024
1 parent 4fd6185 commit 210fc8f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions DriftStakeVoterPlugin/DriftVoterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import queryClient from '@hooks/queries/queryClient'
export class DriftVoterClient extends Client<DriftStakeVoter> {
readonly requiresInputVoterWeight = true

async _fetchRegistrar(realm: PublicKey, mint: PublicKey) {
const { registrar: registrarPk } = this.getRegistrarPDA(realm, mint)
const registrar = await queryClient.fetchQuery(
['Drift', 'Plugin Registrar', registrarPk],
() => this.program.account.registrar.fetch(registrarPk)
)
return registrar
}

constructor(
public program: Program<DriftStakeVoter>,
public devnet: boolean
Expand Down Expand Up @@ -49,8 +58,7 @@ export class DriftVoterClient extends Client<DriftStakeVoter> {
mint: PublicKey,
inputVoterWeight: BN
): Promise<BN | null> {
const { registrar: registrarPk } = this.getRegistrarPDA(realm, mint)
const registrar = await this.program.account.registrar.fetch(registrarPk)
const registrar = await this._fetchRegistrar(realm, mint)
const spotMarketIndex = registrar.spotMarketIndex // could just hardcode spotmarket pk
const driftProgramId = registrar.driftProgramId // likewise
const drift = new Program(DriftIDL, driftProgramId, this.program.provider)
Expand Down Expand Up @@ -142,7 +150,7 @@ export class DriftVoterClient extends Client<DriftStakeVoter> {
voter
)
const { registrar: registrarPk } = this.getRegistrarPDA(realm, mint)
const registrar = await this.program.account.registrar.fetch(registrarPk)
const registrar = await this._fetchRegistrar(realm, mint)
const spotMarketIndex = registrar.spotMarketIndex // could just hardcode spotmarket pk
const driftProgramId = registrar.driftProgramId // likewise
//const drift = new Program(DriftIDL, driftProgramId, this.program.provider)
Expand Down

0 comments on commit 210fc8f

Please sign in to comment.